Thank you for answer, yes now I can see:
result": 5.567611162256132e-144,
but the correct value is 0.0
the line current = map(current/5, 0, 4095, 0, 3300); shows 0,000
but the line sprintf(resultstr, “{“data1”:%d,}”, current); show 5.567611162256132e-144
How can I convert 5.567611162256132e-144 to 0.000
FULL CODE
void loop()
{
Serial.print(“ACS712@A2:”);Serial.print(readCurrent(ACSPin),3);Serial.println(" mA");
delay(150);
}
int determineVQ(int PIN) {
Serial.print(“estimating avg. quiscent voltage:”);
long VQ = 0;
//read 5000 samples to stabilise value
for (int i=0; i<5000; i++) { // esttava 5000
VQ += analogRead(PIN);
delay(1);//depends on sampling (on filter capacitor), can be 1/80000 (80kHz) max.
}
VQ /= 5000;
Serial.print(map(VQ, 0, 4095, 0, 3300));Serial.println(" mV");
return int(VQ);
}
float readCurrent(int PIN) {
int current = 0;
int sensitivity = 100.0;//change this to 100 for ACS712-20A or to 66 for ACS712-30A
//read 5 samples to stabilise value
for (int i=0; i<5; i++) {
current += analogRead(PIN) - VQ;
delay(1);
}
current = map(current/5, 0, 4095, 0, 3300);
sprintf(resultstr, “{“data1”:%d,}”, current);
return float(current)/sensitivity;
}