Help with Voltage divider, sense supply voltage


I’m trying to monitor the voltage of the battery that is powering the Arduino. I’m having to power my project with 4x1.5V AA cells which is cutting it fine, so keeping an eye on the voltage is going to be important. I’m powering two servos and and Xbee transmitter from the same pack. (This set up is working so far, using good fresh cells I’ve got enough power).

I have a voltage divider set up on my power rails and connected to A0 on the Arduino. The servos and Xbee draw their power direct from the power rails, not from the arduino’s +5v pin (learnt from my previous mistake! The arduino can either draw it’s power from the rails, or from USB. Either way the Ground Pin is connected to the -Ve rail.

When the Arduino is powered from USB, it reports the voltage from the power rails accurately, but when I power the Arduino through it’s external power jack from the power rails with everything else, the value of A0 stays at 1024. How can I report the voltage accurately?

Although I’ve read up on Voltage Dividers, and understand the principle, I’ve not found any suggestions what are good values to use for R1 and R2. Obviously I want to conserve as much power as I can so i would have thought that using high Ohm resisters would be best. As I mentioned, the battery is 6V and i’m using the divider to take this down to about 5V. R1 is 2K2 and R2 is 120K, are these good values? There was a fair bit of trial and error in arriving at this point.


If you have two resistors R1, R2 in series, R1 being connected to V and R2 connected to ground, the voltage at the midpoint is given by V * R2 / (R1 + R2).

Using your values, I get 6 * 120 / (122.2), which is 5.89.

Try using something like R1 = 120K, R2 = 22K, which would give 0.93 volts for 6 volts in.

Doh, Sorry! thats a Typo by me, I am using a 22K, not 2.2K.

Are you suggesting that the Large resistor, 120K should be the one connected to Ground (R2)?

I’m more worried right now about the problem with the Arduino not sensing the voltage when powered by the Battery rather than USB.


I get 6 * 120/142 = 5.07. That would read full scale, since its the 5V level. Try the divider the other way up and see if you get a smaller reading.

( I posted a diagram)

the value of A0 stays at 1024

Yes it will because the Arduino takes it’s voltage reference from the power rails. If this is the USB then it is independent of what you are measuring. If you are using the power rails then it is the value produced at the output of the Arduino’s voltage regulator that is taken as the reference.

For a true independent reading you need to derive a reference voltage and feed that into the Ain pin, then change the software so it looks at this pin.

Hi Mike, thanks for the reply.

Could you elaborate a bit more on this process? I’m not sure which pin you mean by the ‘Ain’ pin, do you mean A0 or Vref?


Sorry yes it is the Vref. All voltages are taken with reference to that. By default this is the power rail of the processor chip. However, if you get a stable voltage, feed it in Vref and tell the processor to look at this instead voltages will be measured relative to this. This voltage has to be below the processor’s power rails and greater than 1.2V (otherwise it will be noisy). There are special voltage reference chips you can get to do this. See the playground for more details.