problem reading analog input

Hi,
I would like to read the current of some devices so I have built a PCB with an ACS712 (20A) and arduino mini pro. I have connected as per indicated with their capacitors and I have added a resistor to get zero value when no load connected to the ACS712.

Unfortunately, when no load is connected to the ACS712, I am not getting zero value. I am getting a RAW value of 550 instead of 512, as it should be.
However, if I read the value at the analog input (A7), with a multimeter, on the arduino it is just 2.5v as it should.

What I do not understand is why the arduino is not giving me 512 when 2.5v on the analog A7……...

I have checked power on the arduino is right 5v, stable and I have tried 2 different arduinos with the same results.

I am pretty lost at the moment as no information found when googling.....

Any ideas?

Sketh is attached

acs712.JPG

Most likely, none of your voltage measurements are particularly accurate, and if you use different voltmeters, they will never agree with each other completely.

Use the ADC value of 550 as zero current, and calibrate the ADC readings against known currents through the ACS712.

See this excellent tutorial on calibration.

You should NOT use a pull up resistor with an ACS sensor.
The ACS does NOT output 2.5volt, but VCC/2.
The ACS sensor is ratiometric, so should be powered from VCC of the processor (with default Aref).
You will get about 400 A/D values from this sensor when measuring (one-way) DC current.
So a 20Amp sensor will have a theoretical resolution (steps) of 20/400 = 50mA (+/- 50mA)
Post pictures and code if you want help.
Leo..

Is your meter on the same range when you measure the 2 voltages? to make sure put the meter from GND to the AREF pin, should be close to 5V, before removing the probes, press the range lock button, that should keep the meter from switching to a lower range, then move ONLY the red probe and measure the ACS712 voltage.

Check the spec of the ACS712. There is error in the reading, and because its a hall sensor its not
small either (hall sensors are finnicky, noisy, prone to drift, etc). IIRC this sensor has 1 to 2%
absolute error across the scale.

jremington:
Most likely, none of your voltage measurements are particularly accurate, and if you use different voltmeters, they will never agree with each other completely.

Use the ADC value of 550 as zero current, and calibrate the ADC readings against known currents through the ACS712.

See this excellent tutorial on calibration.

Thanks for your feedback

That could be a practical solution but I rather prefer to investigate why things are not working well.....
Anyway, It would not have solved my case (see the solution I found on next posts)

Do not underestimate arduino accuracy,,,,, I am getting now good results (and stable) with 50ma precision. Although it is a modest precision, quite good for many cases......

MarkT:
Check the spec of the ACS712. There is error in the reading, and because its a hall sensor its not
small either (hall sensors are finnicky, noisy, prone to drift, etc). IIRC this sensor has 1 to 2%
absolute error across the scale.

True, but VCC/2 (zero current) should be reasonably stable.
Leo..

Wawa:
You should NOT use a pull up resistor with an ACS sensor.

I am not using any pull up resistor.......

Wawa:
a 20Amp sensor will have a theoretical resolution (steps) of 20/400 = 50mA (+/- 50mA)

Right!
This is what I am getting now.

I have solve the issue (see later post)

I have find out the solution myself.....

The problem is I am powering the arduino mini with 5v on the RAW pin and then I have 4.61v on the VCC pin and so 4.64 y the reference voltage for the arduino!
Making some maths:
if 5v on the VCC --> 512 (10242.5/5) read when 2.5v on the analog pin.
If 4.64v on the VCC --> 551 (1024
2.5/4.64) read when 2.5v on the analog pin which is was I am just getting.

Solution:
1- Power arduino with 7v to raw pin or 5v direct to VCC pin.
2- Make the calculations considering I get 4.64v where it should be 5v

Both works fine.

I am pretty happy with results having a 50ma accurate and stable system

Thanks to all for your reply’s

irrintxi:
I am not using any pull up resistor.......

Sorry, shouldn't use a pull down resistor (there is one in the diagram you uploaded).

irrintxi:
The problem is I am powering the arduino mini with 5v on the RAW pin

Making some maths:
if 5v on the VCC --> 512 (10242.5/5) read when 2.5v on the analog pin.
If 4.64v on the VCC --> 551 (1024
2.5/4.64) read when 2.5v on the analog pin which is was I am just getting.

Solution:
Make the calculations considering I get 4.64v where it should be 5v

The V-in or raw pin is the input of the 5volt regulator.
The onboard 5volt regulators needs at least 6volt to make a stable 5volt for the board.

Forget about the maths. This sensor is RATIOMETRIC (Google it).

Wrong solution. Don't calculate anything.

A ratiometric sensor, powered from Arduino's 5volt pin (default Aref), is supply independent.

Zero Amp on a 5volt supply will ouput VCC/2 = 2.5volt.
2.5volt with 5volt Aref will give an A/D value of 512.

Zero Amp on a 4volt supply will output VCC/2 = 2volt.
2volt with 4volt Aref will also give an A/D value of 512.
Leo..

Wawa:
Sorry, shouldn't use a pull down resistor (there is one in the diagram you uploaded).

You are right!
As 2.5v is zero current, it does not make sense to use a pulldown resistor.... Nice mistake!!!
Thanks!

Wawa:
Forget about the maths. This sensor is RATIOMETRIC (Google it).

Wrong solution. Don't calculate anything.

Being humble..... I disagree.....
In my particular case it really works nicely.

Wawa:
Zero Amp on a 5volt supply will ouput VCC/2 = 2.5volt.

Right!
This is my case, as the ACS712 is being powered by a regular external 5v power.

Wawa:
2.5volt with 5volt Aref will give an A/D value of 512.

As I am powering the arduino mini with 5v, my reference voltage is 4.64 (stable) --> A/D value of 551 when 2.5v at the analog pin.

Wawa:
Zero Amp on a 4volt supply will output VCC/2 = 2volt.
2volt with 4volt Aref will also give an A/D value of 512.

Not my case as I my acs712 is being powered by external 5v.
I use the same 5v power for the arduino (then 4.64v ref.) and for the ACS712

Definitely, It would have been better a different design:

  • Power arduino with about 7v to have a 5v Aref
  • Power the acs715 with the arduino or external but 5v.
    But……. I have 10 PCB board already made and I would like to used them.

Although I will do it in different way next time, I am reading current with an acceptable accuracy for this particular project so I can stay with it. (I am reading the current with 2 different multimeters and with the arduino, having the same results up to the first decimal value, which is ok for my aplication.

Anyway, I DO APRECIATE your comments!!!!

So you have a zero current A/D value of ~550, because you have powered the sensor from 5volt, and are using a reference voltage of 4.64volt.

Moving the 5volt supply from the raw pin to the 5volt pin (cutting one track) shouldn't be a big problem.
Connecting things wrong, and "fixing" it with code just seems wrong.
Leo..

I finally made the modification powering with external 5v to both: arduino bcc and acs712 sensor and averting goes well now.... 512 value on the analog pun when 0A current.

I m using ACS712 30A with arduino nano. I ran the code below

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

void loop(){
 int sensorvalue = analogRead(A0);
 Serial.println(sensorvalue);
 
 
 delay(2000); 
 
}

and the result is in the attachment. I m getting 102, 103, 104..... as analog values

I could not figure out the reason for this. I should get a value around 512. Anyone please help me

irrintxi:
Hi,
I would like to read the current of some devices so I have built a PCB with an ACS712 (20A) and arduino mini pro. I have connected as per indicated with their capacitors and I have added a resistor to get zero value when no load connected to the ACS712.

Unfortunately, when no load is connected to the ACS712, I am not getting zero value. I am getting a RAW value of 550 instead of 512, as it should be.

Firstly check the accuracy spec for the ACS712 from the datasheet, second check for any nearby magnet,
even a small one could radically distort the reading from a hall current sensor, thirdly measure all the
voltages at the ACS712 w.r.t ground at the Arduino pin, and measure the Vcc voltage at the arduino.

If the sensor ground or voltage differ from the Arduino one's you have routed current through sensor
ground or supply wiring, which is going to throw readings - this is why star-grounding should be used
for sensors and sensitive analog circuitry.

The ADC measure voltages relative to the Arduino's Gnd and Vcc, it cannot correct for discrepancies of
ground or supply at the sensor itself.

And hall sensors are just magnetometers placed near the current path to be sensed - as I recall there's
no magnetic shielding in these chips, there isn't room.

Sudipta_mandal94:
I m using ACS712 30A with arduino nano. I ran the code below

void setup(){ 

Serial.begin(9600);
}

void loop(){
int sensorvalue = analogRead(A0);
Serial.println(sensorvalue);

delay(2000);

}



and the result is in the attachment. I m getting 102, 103, 104..... as analog values
![arduino asc712.png|1363x731](upload://m1nqCEriFY32yQQKGDMe5SYVupU.png)

I could not figure out the reason for this. I should get a value around 512. Anyone please help me

Hi.
You are only reading the raw values. You have to do some maths to work out the current.
you have here an exemple:

/*
Measuring Current Using ACS712
*/
const int analogIn = A0;
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(){

RawValue = analogRead(analogIn);
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);

}