Good morning.
I am trying to measure the power of an electrical device. I use an SCT013 with a SEN0211 ( https://www.tme.com/us/es/details/df-sen0211/otros-sensores/dfrobot/sen0211/ )
I copied an example and tried it. It doesn't measure correctly. The truth is that I don't really know what I'm doing. Does anyone know or have an example that I can follow to correctly measure the power? I'm attaching the code I'm using and it doesn't measure correctly.
I have tried it with different Arduinos, please note:
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
Thanks.
void setup() {
Serial.begin(9600);
//analogReference(INTERNAL);
//analogReference(INTERNAL1V1); //solo Arduino Mega
}
void loop() {
float Irms=get_corriente(); //Corriente eficaz (A)
float P=Irms*220.0; // P=IV (Watts)
Serial.print("Irms: ");
Serial.print(Irms,3);
Serial.print("A, Potencia: ");
Serial.print(P,3);
Serial.println("W");
//delay(100);
}
float get_corriente()
{
float voltajeSensor;
float corriente=0;
float Sumatoria=0;
long tiempo=millis();
int N=0;
while(millis()-tiempo<500)//Duración 0.5 segundos(Aprox. 30 ciclos de 60Hz)
{
voltajeSensor = analogRead(A3) * (3.3 / 1023.0);////voltaje del sensor
corriente=voltajeSensor*20.0; //corriente=VoltajeSensor*(20A/1V)
Sumatoria=Sumatoria+sq(corriente);//Sumatoria de Cuadrados
N=N+1;
delay(1);
}
Sumatoria=Sumatoria*2;//Para compensar los cuadrados de los semiciclos negativos.
corriente=sqrt((Sumatoria)/N); //ecuación del RMS
return(corriente);
}