Go Down

Topic: How to measure voltage from 12V battery (Read 11432 times) previous topic - next topic



How can I measure the voltage of a 12V battery that is being used to power my Arduino? I am converting 12V -> 5V to power the board, but I am trying to figure out a way to a) measure the voltage from the external battery b) be able to convert the 5V reading to 12V.  I originally thought that I could do this with analogRead, but it doesn't seem to be working.

Thanks for any help or suggestions.


Jul 18, 2014, 12:58 am Last Edit: Jul 18, 2014, 01:02 am by Peter_n Reason: 1
Is the Arduino running on a good and stable 5V ?
If it is, you can use that as the reference. It is the default.

You need a voltage divider. That are just two resistors.
You can see one here: http://www.instructables.com/id/DIY-Amp-Hour-Meter-Arduino/
Don't calculate the resistor so that 12V becomes 5V. But use for example resistors so that 20V becomes 5V.

When you use the internal voltage reference, you have to use resistors to bring the 12V to 1.1V.

You might need to use the average of a few analogRead samples, for higher accuracy.


Jul 18, 2014, 01:15 am Last Edit: Jul 18, 2014, 03:00 am by groundfungus Reason: 1
If you plugged 12V into an analog port that port,at least, is probably toast.  The max you can apply to an analog port is VCC + 0.5V.


I am using a mega2560, and am having trouble using the sketch provided from http://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/  Does anyone have any suggestions?


Do you want to measure the voltage of the battery, about 12V ?
Or do you want to measure the 5V of the Arduino board itself ? That should be 5V, so why do you want to measure it ?

That so called "secret" voltmeter, makes it able that the ATmega2560 chip can measure it's own 5V voltage of the Vcc pin. That can be useful when the 5V is not stable. It is not even a 'secret' and it is not a trick, it is about setting the internal mux so the Vcc can be measured against the internal reference voltage. It is usefull for other ATmega chips that run directly on batteries.

When you want to measure the 12V battery, use the resistor divider that I wrote about, and please forget about that useless silly 'secret' voltmeter.


Sorry about that peter n, i thought it would be useful thats all. :)


voltage diviced have ok,
 but how i read voltage at rotary switch if i add 4 pin come in 12 volt and need read arduino A0 what position have used,

 1,2,3,4 pin come 12 volt, and i think use 14k,20k,30k,50k ohm resistor ewery pin and 10k resistor to ground, and center take out to arduino analog pin read what volt have and what position is connected.

think me wrong voltage divided ? R1=14k,20k,30k,50k, out come 2,3,4,5 volt, R2 have 10k ohm.

and how i read analogread thats ?

and make case what i want do different position. or what is best way read rotary switch position ? simple way ?
 i not has code arduino lot,
and want learn how read analog and use 4 different position and do case ewery position different program.

if pos=1 do pump x time, if pos=2 do y time, if pos=3 do z time etc,etc,

case 1 do somethink break, case 2: do somethink break: case3, case 4, etc,


I can't understand Reply #7.

Make a pencil drawing showing how everything is connected and post a photo of the drawing.

I suspect your question has nothing to do with the subject of the earlier posts in this Thread.

Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up