I found the problem. was my severals nodeMCU connected on my computer at the same time!!! OMG! so many ports, and I was uploading the code to the wrong nodemcu…
I did the code. the loop ask the read function using SimpleTimer, 1 time per second and send the value to the blynk on V13 I used a GAUGE widget.
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
char auth[] = "...";
char ssid[] = "....";
char password[] = "...";
const int sensorIn = A0;
int mVperAmp = 66; // use 100 for 20A Module and 66 for 30A Module
double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;
SimpleTimer timer0;
void readACS712() {
Voltage = getVPP();
VRMS = (Voltage/2.0) *0.707;
AmpsRMS = (VRMS * 1000)/mVperAmp;
Serial.print(AmpsRMS);
Serial.println(" Amps RMS");
Blynk.virtualWrite(V13, AmpsRMS);
pinMode(sensorIn, INPUT);
}
void setup(){
Serial.begin(9600);
Blynk.begin(auth, ssid, password);
timer0.setInterval(1000L, readACS712);
}
void loop(){
Blynk.run();
timer0.run();
}
float getVPP()
{
float result;
int readValue; //value read from the sensor
int maxValue = 0; // store max value here
int minValue = 1024; // store min value here
uint32_t start_time = millis();
while((millis()-start_time) < 1000) //sample for 1 Sec
{
readValue = analogRead(sensorIn);
// see if you have a new maxValue
if (readValue > maxValue)
{
/*record the maximum sensor value*/
maxValue = readValue;
}
if (readValue < minValue)
{
/*record the maximum sensor value*/
minValue = readValue;
}
}
// Subtract min from max
result = ((maxValue - minValue) * 5.0)/1024.0;
return result;
}