# ACS712 current sensor code problem

Hi guys, I have a question to ask. It is about the coding of the ACS712 current sensor that I found on internet.

``````/*
Measuring Current Using ACS712
*/
int mVperAmp = 185; // use 100 for 20A Module and 66 for 30A Module
int RawValue= 0;
int ACSoffset = 2500;
double Voltage = 0;
double Amps = 0;

void setup(){
Serial.begin(9600);
}

void loop(){

Voltage = (RawValue / 1024.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); // the '3' after voltage allows you to display 3 digits after decimal point
Serial.print("\t Amps = "); // shows the voltage measured
Serial.println(Amps,3); // the '3' after voltage allows you to display 3 digits after decimal point
delay(2500);

}
``````

Actually what is ACSoffset and why is 2.5v?

Because it's for measuring AC current and was shifted from - 2.5v + 2.5v to 0 +5v

But if I wanted to measure DC current from a solar panel?

menloon:
But if I wanted to measure DC current from a solar panel?

So you will be using only halve of diapason.

menloon: But if I wanted to measure DC current from a solar panel?

The 2500 has nothing to do with AC or DC. The ACS712 is a bi-directional current sensor, that outputs half of it's own supply with no current going through the sensor. Meaning you can measure DC charge and discharge currents, or positive/negative going currents with AC. It also means you have only half of the A/D range if you are only going to use it for one-way current. And with the 10-90% span of the sensor, you only have 40% of the A/D to work with (about 410 values). So pick your sensor range wisely (there are three types of ACS712).

Maybe you should also look at an INA219 breakout board. Leo..

Wawa: The 2500 has nothing to do with AC or DC. The ACS712 is a bi-directional current sensor, that outputs half of it's own supply with no current going through the sensor. Meaning you can measure DC charge and discharge currents, or positive/negative going currents with AC. It also means you have only half of the A/D range if you are only going to use it for one-way current. And with the 10-90% span of the sensor, you only have 40% of the A/D to work with (about 410 values). So pick your sensor range wisely (there are three types of ACS712).

Maybe you should also look at an INA219 breakout board. Leo..

Thanks for the advice. I guess I know what to do next =)