Go Down

Topic: analogRead not showing expected results (Read 515 times) previous topic - next topic

I have an Arduino Uno powered from USB.  I am trying to get the voltage of a 12V battery through analog pin 0.

I have 3 x 10K resistors in series (+12V  --- R1 ---  R2 --- R3 --- GND) .  I needed 3 resistors for the voltage divider, as I don't have any larger than 10K at the moment.

Connecting the multimeter to the battery terminals reads 12.81V and between R3 it reads 4.23V, which is around the expected value.

When I connect a wire between R2 and R3 to analogue pin 0 and read the value using analogRead(0)., It returns 921.  This appears higher than I expected which is 866 (866 * 5/1023 = 4.23).

What could be wrong?

groundfungus

By default, the analog reference is the 5V supply voltage.  Measure the real supply voltage and substitute that  for the 5 in the 5/1024 and see if it is closer.  With USB I would expect the supply is lower than 5.00V.

James C4S

The USB spec allows the USB voltage to be between 4.75 and 5.25v.

A reading of 921 on 4.23v suggests your VCC (5V) is only 4.7v.

You aren't putting 5V into Vin or the Barrel Jack are you?
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

polymorph

You might consider dividing the voltage down further and using the internal 1.1V reference. Otherwise, you will have to recalibrate if you move the Arduino to a different power supply or to a different computer, or even just a different USB port.

In any case, Aref and AVcc should each have a 0.01uF or 0.1uF bypass capacitor to ground with -very- short wires between.
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - tinyurl.com/q7uqnvn
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

Just for giggles, did you connect the negative battery terminal to Arduino ground? If you didn't, then the reading could float anywhere between 0 and 1023.

Most likely, the 5 V at the Arduino isn't really 5 V. Use a 12 V supply at the power jack and check it again.

tack

What exactly are your resistor values and the input voltage Vcc?

You say you don't have anything larger than 10k so would it be a corect assumption to believe you are using 3 x 10k, aiming for a 20k/10k divider?

To calculate the analog input value accurately you need to know the actual Vcc and account for all resistance in the divider, including the pin input impedance.

123Splat

To expound upon what Tack is saying, 10K 'marked' resistors don't always measure 10K Ohms (tolerance and temp coeff).  But, Poly and James are most likely the ones with the most appropriate responses (IMHO).

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy