I'm getting .08A when i hook up my acs712 without load.. or no current being read..
how can I make it accurate? i'm trying to read atleast .05A to it's max(20a)..or just up to 15A..
here's the code:
const int currentPin = A0;
const unsigned long sampleTime = 100000UL; // sample over 100ms, it is an exact number of cycles for both 50Hz and 60Hz mains
const unsigned long numSamples = 250UL; // choose the number of samples to divide sampleTime exactly, but low enough for the ADC to keep up
const unsigned long sampleInterval = sampleTime/numSamples; // the sampling interval, must be longer than then ADC conversion time
const int adc_zero = 510; // relative digital zero of the arudino input from ACS712 (could make this a variable and auto-adjust it)
double P=0;
double E=0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
unsigned long currentAcc = 0;
unsigned int count = 0;
unsigned long prevMicros = micros() - sampleInterval ;
while (count < numSamples)
{
if (micros() - prevMicros >= sampleInterval)
{
int adc_raw = analogRead(currentPin) - adc_zero;
currentAcc += (unsigned long)(adc_raw * adc_raw);
++count;
prevMicros += sampleInterval;
}
}
float rms = sqrt((float)currentAcc/(float)numSamples) * (75.7576 / 1024.0);
if (rms < 0.0819)
rms=0;
P=rms*240;
E=E+(P/3600);
Serial.print("Power is equal to: ");
Serial.print(P,3);
Serial.println(" Watts");
Serial.print("Energy is equal to: ");
Serial.print(E,4);
Serial.println(" kWh");
Serial.print("The current is ");
Serial.print(rms,5);
Serial.println(" Amps.");
Serial.println(" ");
delay(1000);
}