Instantaneous AC Current Values Using ACS 712 Arduino Code

Hi frndz

I need to find instantaneous values of AC current

I found a code for ACS 712 on another post and changed it a bit because i only need instantaneous current values

the readings i got for a particular device were like the the following

almost positive extreme readings (6.22 Ampere)
then 0.01 somthng
then negative extreme readings (- 5.92 Ampere)

nd the pattern continues like this

nd i expected to get very close readings (like 1.00 A then 1.01A then 1.02A) but this didnt happen but it should since i mean measuring current after 400 micro seconds

Plz tell me what is the prob in the following code

sampleinterval = 0.1 sec
num of samples = 250
sample interval = 400us

const int currentPin = 3;
const unsigned long sampleTime = 100000UL;                           
const unsigned long numSamples = 250UL;                               
const unsigned long sampleInterval = sampleTime/numSamples; 
const int adc_zero = 510;                                                     

void setup()

void loop()
  float currentAcc = 0;

  unsigned long prevMicros = micros() - sampleInterval ;
    if (micros() - prevMicros >= sampleInterval)
      int adc_raw = analogRead(currentPin) - adc_zero;
      currentAcc = (float)currentAcc *(50.0/1024.0);      
      prevMicros += sampleInterval;

I need some help its urgent

Hi, I think you had better read up on how the AtoD conversion is done and how long it takes.
Look up the Atmel spec manual for the CPU chip in the arduino.
It will have a chapter on AtoD and the speed at which it takes to go from analog input to digital byte output.

Tom... :slight_smile: