SEN0211 sensor is never zero, also wrong output
I'm trying to measure Power from an SEN0211 sensor using a Firebeetle 2 ESP32-E. I changed the code (VREF and 4096 instead of 1024 in the division of VoltageVirtualValue, code posted below)
the sensor reads ~.85A even when not any power is drawn, and when I hook it up to a 830W toaster (~3.7A@220V, I measured it with a seperate tool) it reads ~2.2A.
The output of the sensor non-zero even when its not conneceted to anything, so a higher precision ADC probably won't make any difference. Is my sensor malfunctioning?
Thanks in advance for anyone who can help me :) Anyways, here's my code, mostly identical from the product page:
/*!
* @file readACCurrent.
* @n This example reads Analog AC Current Sensor.
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (https://www.dfrobot.com)
* @licence The MIT License (MIT)
* @get from https://www.dfrobot.com
Created 2016-3-10
By berinie Chen <[email protected]>
Revised 2019-8-6
By Henry Zhao<[email protected]>
*/
const int ACPin = A2; //set arduino signal read pin
#define ACTectionRange 20; //set Non-invasive AC Current Sensor tection range (5A,10A,20A)
// VREF: Analog reference
// For Arduino UNO, Leonardo and mega2560, etc. change VREF to 5
// For Arduino Zero, Due, MKR Family, ESP32, etc. 3V3 controllers, change VREF to 3.3
#define VREF 3.3
float readACCurrentValue()
{
float ACCurrtntValue = 0;
float peakVoltage = 0;
float voltageVirtualValue = 0; //Vrms
for (int i = 0; i < 5; i++)
{
peakVoltage += analogRead(ACPin); //read peak voltage
delay(1);
}
peakVoltage = peakVoltage / 5;
Serial.println(peakVoltage);
voltageVirtualValue = peakVoltage * 0.707; //change the peak voltage to the Virtual Value of voltage
/*The circuit is amplified by 2 times, so it is divided by 2.*/
voltageVirtualValue = (voltageVirtualValue / 4096 * VREF ) / 2;
ACCurrtntValue = voltageVirtualValue * ACTectionRange;
return ACCurrtntValue;
}
void setup()
{
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
float ACCurrentValue = readACCurrentValue(); //read AC Current Value
Serial.print(ACCurrentValue);
Serial.println(" A");
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
}
Well, it kinda stopped doing it by itself, but thanks for the tip. Now it starts as zero, as it should, and after correcting the power factor value, it shows the toaster's Amps accurately. The thing is it doesn't pick up my PC's power at all. All zeroes. Does it have a minimum value? I have the 20A version and I think I should've had the 5A one for smaller currents
Yiannikos.PavlisUse the analogRead() function to log raw ADC values when the sensor is idle. You can then subtract the average idle value (offset) from subsequent readings:
int offset = 0;
for (int i = 0; i < 100; i++) {
offset += analogRead(ACPin);
delay(10);
}
offset = offset / 100; // Average idle ADC value