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