Measuring Battery Voltage Issue

Hi there,

I'm just getting used to my Arduino board and I'm trying to measure the voltage of the cell, so that ultimately I can flash an LED on my project when the batteries need replacing.

I followed this guide: and am sure that I've wired everything correctly. when the battery is switched on, the output values in the console are roughly -1910.00. Any idea what I'm doing wrong? From the calculations in that example, should this be returning values around the 5 mark if wired correctly?

Also, at what kind of voltage drop would the board stop working?

Any help would be appreciated. Thank you.


Without seeing your code and a diagram of how things are wired it is impossible to say.

Negative numbers where positive ones are expected often indicates an overflow - using an int when a long is required, for example.


The wiring and code are the same as the example. I'm wondering if the code and diagram from that project should produce these values? The guy that wrote the article didn't show the output values. But I'm assuming the values should be around 5.

And the raw val from the battery on analog pin 0 is roughly 380.

I have to guess the since you did everything exactly like the link, then the link if faulty. there can be no other conclusion, right ?

using the above logic, you need to figure out how to do it on your own.

run a sketch


/ examples / analog / analoginput

follow the example.

you should get values.

if that works, then you are on to your next step. swap out the pins from the pot for your resistors.

since this is of a new design, you really should draw a simple schematic, show the battery, show the arduino, show the pin you are connecting to, label the values of the resistors.

then, with your own design, post a schematic and your code.

==================================================================== It is hard to fill a cup that is already full.

why not serial output the a/i value, the batteryPin

then also, resistorFactor

on the same line with the volts.?

then you can do the math and maybe see which value is wrong.

by the way, posting your code gives us the tools to help you. since it is not working as you expect, then either the code on the next is wrong, or your code has a typo or some such.

Is this the code you are using?

DisplayMoreThan5V sketch
prints the voltage on analog pin to the serial port
Do not connect more than 5 volts directly to an Arduino pin.

const int referenceVolts = 5; // the default reference on a 5-volt board
//const float referenceVolts = 3.3; // use this for a 3.3-volt board

const int R1 = 3000; // value for a maximum voltage of 20 volts
const int R2 = 1000;
// determine by voltage divider resistors, see text
const int resistorFactor = 255 / (R2/(R1 + R2));
const int batteryPin = 0; // +V from battery is connected to analog pin 0

void setup()

void loop()
int val = analogRead(batteryPin); // read the value from the sensor
float volts = (val / resistorFactor) * referenceVolts ; // calculate the ratio
Serial.println(volts); // print the value in volts

I really don’t understand why you didn’t post it to save me the trouble !!!

I’m not sure the forumla for calculating the voltage is correct

If you don’t have a voltage divider and you feed (say) 2.5v to the ADC you will get a value of 511 (1023/2).
So the simple formula to work out the voltage is 5 / 1023 * value.

If you have a voltage divider (say it divides by 4) then the actual voltage will be 5 / 1023 * value * 4

I presume you are NOT trying to measure the voltage (5v) that the Arduino runs at, or, put another way, I presume your battery you want to measure provides 7 to 12v and is connected to the Arduino power input socket.