BLYNK
BLYNK.IO       📲 GETTING STARTED       📗 DOCS       👉 SKETCH BUILDER

AC Power Monitor ACS712 int rZero=

Hi community !

Hope you’re well !

I’m testing Power monitor from @Gunner ( C++ Blynk (Legacy) - Code Examples for Basic Tasks - #18 by Gunner ) #8

int rZero = 511; // For illustrative purposes only - should be measured to calibrate sensor.

Here i’ve to measured something for calibration but I don’t understand what this coefficient corresponds to.

Somebody know ?

Thanks

That parameter is used to ensure that you get a zero current reading when there is no load.

Due to the resolution of the 20A device that is used in the example, the reading could fluctuate by around 0.1 Amps, so you may never get a consistent zero reading.

Pete.

Ok and what about 5A ( wich i use ) ?

With unplugged outlet i’ve 0.06 A and 11 Watt

My sketch with 5 / 20 / 30 AACS712 modification

//#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>


char auth[] = "s1oz6Yyf1QW34M-GqJjlQbj4h2dqEY1l";
char ssid[] = "indoor";
char pass[] = "indoorwifi";

const int sensorIn = A0;
int mVperAmp = 185; // use 100 for 20A Module and 66 for 30A Module and 185 for 5A
double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;

BlynkTimer timer;

WidgetTerminal terminal(V1);

void setup() {
  Serial.begin(9600);
  
  //Blynk.begin(auth, ssid, pass, IPAddress(10,3,141,1), 8080);
  Serial.println("Capteur courant");

  timer.setInterval(2000L, SensorRead);
}



void loop() {
  Blynk.run();
  timer.run();
}



void SensorRead() {
  Voltage = getVPP();//
  VRMS = (Voltage / 2.0) * 0.707;
  AmpsRMS = (VRMS * 1000) / mVperAmp;
  Blynk.virtualWrite(V0, 0.9 * AmpsRMS * 230);  // To Gauge Widget @ .9pf and 230vac
  //terminal.print(AmpsRMS);  // To Terminal Widget
  //terminal.print(" Amps - ");
  //terminal.flush();
  Serial.print(" Amps "); // To arduino terminal
  Serial.println(AmpsRMS);// To arduino terminal
  
  Serial.print(" Watt "); // To arduino terminal
  Serial.println(0.9 * AmpsRMS * 230);  // To arduino terminal

  //Serial.println(" VRMS "); // To arduino terminal
  //Serial.print(VRMS);  // To arduino terminal
}




float getVPP() {
  float result;
  int readValue;  //value read from the sensor
  int maxValue = 0;  // store max value here
  int minValue = 1023;  // store min value here
  uint32_t start_time = millis();
  while ((millis() - start_time) < 1500) {  // sample for 1 Sec
    readValue = analogRead(sensorIn);  // see if you have a new maxValue
    if (readValue > maxValue) {
      maxValue = readValue;  // record the maximum sensor value
    }
    if (readValue < minValue) {
      minValue = readValue;  // record the minimum sensor value
    }
  }
  // Subtract min from max
  result = ((maxValue - minValue) * 5.0) / 1023.0;
  return result;
}



void ac_read() {
  int rVal = 0;
  int sampleDuration = 100;  // 100ms
  int sampleCount = 0;
  unsigned long rSquaredSum = 0;
  int rZero = 511;   // For illustrative purposes only - should be measured to calibrate sensor.
  uint32_t startTime = millis();  // take samples for 100ms
  while ((millis() - startTime) < sampleDuration) {
    rVal = analogRead(A0) - rZero;
    rSquaredSum += rVal * rVal;
    sampleCount++;
  }
  double voltRMS = 5.0 * sqrt(rSquaredSum / sampleCount) / 1024.0;
  // x 1000 to convert volts to millivolts
  // divide by the number of millivolts per amp to determine amps measured
  // the 20A module 100 mv/A  (so in this case ampsRMS = 10 * voltRMS / 5A 185 mv/A
  double ampsRMS = voltRMS * 18.5;
}

This is for Watt value ( P = U * I ) :

Serial.println(0.9 * AmpsRMS * 230); → 0.9 for gauge in blynk A and V

I don’t know what is wrong

I don’t understand your question.

Pete.

With unplegged outlet ( no electrical consumption ) i’ve this value on terminal : 0.06 A and 12 W wich is wrong value.

I looking for why i’ve this wrong value

Because you’ve not adjusted the rZero variable to calibrate your hardware.

Pete.

Ok that’s what I thought, and what is the way to get the calibration value?

Trial and error.

Pete.

I change for 510 / 509 / 400 / 100 / 1000 nothing is changing on my value terminal value

Then I’d suggest that you have a problem, maybe with your wiring, or the sensor, or your changes to the code.

Pete.

Wiring is ok, and same resultat with other ACS712…

Can you look if code is good ?

Download a example sketch from the internet(without blynk code).

Get that to work. If you get what you want ! Just add the blynk and you will be done.

This is the easiest way to troubleshoot.

I’d suggest you start by running the sketch (with appropriate modifications) on a Mega or NodeMCU so that you have a useable serial port for debugging, then add-in some sensible serial print commands to allow you to understand what values you are seeing at the various stages in the process.

As @Madhukesh says, it’s always best to run a non-Blynk version first, but you do need access to a useable serial port and you won’t have that if you’re using an Uno + ESP-01.

Pete.

1 Like

I’ve value from this, esp8266 and serial monitor. I know best way it’s start with sketch without Blynk, that’s i do

I don’t understand what that means.

Pete.

My value( Watt and Amp ) come from serial monitor of Arduino IDE, not from blynk.

So you’re running it on different hardware to @Gunner’s example. I didn’t spot that in your code.

The Arduino Uno uses 0 - 5v for its ADC input range.

The bare ESP8266 uses 0 - 1v as it’s ADC input range, but the NodeMCU has an onboard voltage divider which changes this to 0 - 3.3v. Both use a 10-bit ADC, so the output value is 0 - 1023 (same as the Arduino Uno).

You may need to amend your circuit so that the output from the ASC712 is at a useable level for whatever ESP8266 based board you are using, and/or change the software so that it works correctly.

Pete.

Hi Pete !

I just thought about it, but I have to be able to use a voltage divider bridge to bring the signal back to 1 Volt, right?

Not if you’re using a NodeMCU.

Pete.

I’m using a NodeMCU, but I don’t understand what I should do…

Could you show me?