ACS712 Current Sensor Code

I need help with the code to read the measured value from ACS712 current sensor, Can't manage to convert the sensor output voltage into current. Also i can't figure out how to identify the current direction (My project includes battery charging and discharging, so it will be useful to know).

I'm pretty sure my connections are done right, and i do get Vcc/2 (2.5 V) sensor output voltage (measured by multi-meter) at no load (no current)

I'm using Arduino UNO
Current sensor datasheet is attached

ACS712-Datasheet.pdf (643 KB)

Ok, Here is what i've reached so far, i found this code on http://www.lucadentella.it/en/2011/11/29/sensore-di-corrente-con-arduino

void setup() {
 
  Serial.begin(9600);
}
 
void loop() {
 
  float average = 0;
  for(int i = 0; i < 1000; i++) 
  {
    average = (average + (((0.0264 * analogRead(A0)) - 13.51)/1000));
    delay(1);
    
  }
  Serial.print (average, 3);
  Serial.print("   ");
  Serial.println(analogRead(A0));
   
}

it doesn't get me accurate readings though, don't know what seems to be the problem.

Hey, hope this helps! :wink: :smiley:

http://arduinosensors.com/index.php/interfacing-a-hall-effect-current-sensor-with-an-arduino/