I'm trying to measure current with acs712 30A current sensor connecting to NodeMCU-32S but I'm getting wrong and unstable values. For zero current the ADC pin should read value of 2048 (esp has 12 bit sensitivity) but instead I'm getting values about 2740-2760. So first I have problem with incorrect value and second is unstable reading. Basically the whole thing look like:
simulate this circuit – Schematic created using CircuitLab
My test code is:
enter dcode here
#include <stdint.h>
#include "esp_err.h"
#include "driver/adc.h"
const int analogIn = 34;
int mVperAmp = 66; // 66 mV/A output sensitivity
int RawValue= 0;
int ACSoffset = 5500/2;
double Voltage = 0;
double Amps = 0;
void setup(){
Serial.begin(115200);
pinMode(analogIn, INPUT);
}
void loop(){
RawValue = analogRead(analogIn);
Voltage = (RawValue / 4096.0) * 5000; // Gets you mV
Amps = ((Voltage - ACSoffset) / mVperAmp);
Serial.print("Raw Value = " ); // shows pre-scaled value
Serial.print(RawValue);
Serial.print("\t mV = "); // shows the voltage measured
Serial.print(Voltage,3);
Serial.print("\t Amps = ");
Serial.println(Amps,3);
delay(250);
}
Thanks.