Pages: [1]   Go Down
Author Topic: analogRead not showing expected results  (Read 457 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

BCC AZ USA
Offline Offline
Edison Member
*
Karma: 38
Posts: 1335
It gets hot so it must be working
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Fort Lauderdale, FL
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6144
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.c

Lacey, Washington, USA
Offline Offline
Faraday Member
**
Karma: 164
Posts: 2575
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Steve Greenfield AE7HD
CET Consumer Electronics and Computer
Please don't read your attitudes into my messages

Alabama, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 40
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

UK
Offline Offline
God Member
*****
Karma: 17
Posts: 569
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Texas, land of the free, home of the stupid
Offline Offline
Sr. Member
****
Karma: 5
Posts: 268
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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).
Logged

Pages: [1]   Go Up
Jump to: