Amperimeter SEN0211 and SCT013

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);
}

Hi, @aprentik

Can we please have a circuit diagram?
An image of a hand drawn schematic will be fine, include ALL power supplies, component names and pin labels.
Please not a Fritzy picture thing.

nofritzy

Thanks.. Tom.. :smiley: :+1: :australia: :coffee:

In the image it is in A2 and in my code it is in A3. But here you can see the assembly.
Thanks

Solved, works fine.
I put everything back together again, following the example and it works fine for me now. I think I had a bad contact in the feed.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.