ac current meter using acs758 hall sensor

dc42:
The max value you can read is indeed 1023, but the correct value to use in the calulation is 1024. See section 24.7 of the atmega328p datasheet.

Thank you for this info!

dc42:
Are you trying to measure alternating current? If so, you need to average the square of the current, and take the square root of the average (that's what RMS means). Easiest way is to subtract the zero-current value (512 or thereabouts) from the raw readings, square that, and add it to an accumulator variable. When you have accumulated enough samples, take the square root if the accumulator and divide by the number of readings.

Yes ac current.

so,
for AC current something like this

samplesnum = 100;
adc_zero = 512; //as read when there is no current on the load
sensitivity = 0.04; //as read from datasheet
for(i=0; i<samplesnum ; i++) 
  adc_raw = analogRead(1);
  currentacc += (adc_raw - adc_zero) * (adc_raw - adc_zero); //subtract the zero-current value (512 or thereabouts) from the raw readings, square that, and add it to an accumulator variable
}
currentac = sqrt(currentacc)/samplesnum; //take the square root if the accumulator and divide by the number of readings.

for DC current something like this

adc_zero = 512; //as read when there is no current on the load
sensitivity = 0.04; //as read from datasheet
currentdc = (adc_raw - adc_zero) * 5/(sensitivity * 1024)

right?