Go Down

### Topic: measuring battery voltage (Read 2798 times)previous topic - next topic

#### arduinopi

##### Dec 13, 2012, 09:13 pm
I am wondering how to measure the voltage of a 12 volt lead acid battery with the arduino's analogRead. I know I need a voltage divider but which kind? what are the best values of resistance to use? what values are safer? I dont want a fully charged battery that reads 14 volt to send more than 5 volts to my arduino.
All of my projects --> http://www.frankmagazu.com/

#### dc42

#1
##### Dec 13, 2012, 09:53 pm
I would use 100K from pin to ground and 200K from pin to +12V. Also a 10nF or 100nF capacitor from pin to ground. Then you will get 1/3 of the voltage yo are trying to measure on the analog input. The 200K is high enough to limit the current into the pin protection diode to a safe value even if the voltage exceeds 15V.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

#### retrolefty

#2
##### Dec 14, 2012, 02:35 am
But the Arduino analog input pins really wants to see a source impedance of 10k ohms or less for best results. He may have to take multiple analog reading and average the results if working with higher resistances.

Lefty

#### Chagrin

#3
##### Dec 14, 2012, 06:16 am
As lefty just said, the impedance must be 10K or less. That means the first resistor must be 10K or less.

10K/4.7K is the best choice. That should result in a voltage reading of (14.4V * 4.7K / (10K + 4.7K)) 4.6V on your analog pin for a battery charged to 14.4V and the total resistance (10K + 4.7K = 14.7K) means you're leaking very little amperage (14.4V / 14.7K).

#### dc42

#4
##### Dec 14, 2012, 07:55 am

But the Arduino analog input pins really wants to see a source impedance of 10k ohms or less for best results. He may have to take multiple analog reading and average the results if working with higher resistances.

Lefty

Not necessary if you only want to measure slowly varying signals and don't need the full 10-bit accuracy. The input resistance of the ADC is given as 100Mohms typical in the datasheet. There is an issue in ensuring that the sample capacitor can charge between setting the multiplexer and starting the conversion, but that is easily solved by either inserting a small delay in the analogRead code or by connecting a capacitor to the analog pin, as I suggested in my post.

I used a potential divider made from two 4.7Mohm resistors to monitor the voltage of a 9V battery voltage in a recent project. This was for a system that had no power switch and put the mcu in power down mode when turned off, so it was important that the potential divider didn't drain the battery. Using such a high source resistance introduces an error of around 2.5%, but for a battery monitor this was acceptable.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

#### retrolefty

#5
##### Dec 14, 2012, 08:00 am

But the Arduino analog input pins really wants to see a source impedance of 10k ohms or less for best results. He may have to take multiple analog reading and average the results if working with higher resistances.

Lefty

Not necessary if you only want to measure slowly varying signals and don't need the full 10-bit accuracy. The input resistance of the ADC is given as 100Mohms typical in the datasheet. There is an issue in ensuring that the sample capacitor can charge between setting the multiplexer and starting the conversion, but that is easily solved by either inserting a small delay in the analogRead code or by connecting a capacitor to the analog pin, as I suggested in my post.

I used a potential divider made from two 4.7Mohm resistors to monitor the voltage of a 9V battery voltage in a recent project. This was for a system that had no power switch and put the mcu in power down mode when turned off, so it was important that the potential divider didn't drain the battery. Using such a high source resistance introduces an error of around 2.5%, but for a battery monitor this was acceptable.

As I said, when dealing with higher impedance sources wired to arduino analog input pins, there are issues to be aware of and dealt with or not as one pleases.

Lefty

#### jackrae

#6
##### Dec 14, 2012, 03:09 pm
Just to help clarify (hopefully) for those confused by Telecommando's serial and parallel considerations for "equivalent circuit".  When considering the supply impedance the calculation is based upon the 10k in parallel with the series combination of 20k + source impedance.  On the basis that the battery has a very low internal impedance (or resistance) then the 20K + source is effectively only 20K + 0  so now we have the equivalent circuit of 10k in parallel with 20k since the battery effectively "disappears" when considering resistances

#### oric_dan

#7
##### Dec 14, 2012, 06:18 pm
Back to the source of it all,

http://en.wikipedia.org/wiki/Th%C3%A9venin's_theorem

#### oric_dan

#8
##### Dec 14, 2012, 07:51 pm
After Ohm's Law, Thevenin's Theorem is probably the single most useful thing to know when
it comes to interfacing circuits together, eg sensors to amps and sensors to A/D converters.
You should study it till it's second-natured.

Then, you can extend it easily to impedances. Eg, for a ckt with capacitors, like an RC low-pass
filter, where the R is a voltage divider, for instance, you first reduce the v.div to its Thevenin
equivalent resistance, and then solve the low-pass by inspection, eg F3db = 1/(2*pi*Rth*C).

#### dhenry

#9
##### Dec 14, 2012, 08:39 pm
Quote

10k is the magic number.

If you have to go above it, use a small capacitor there.

#### lemming

#10
##### Dec 14, 2012, 11:27 pm
Quote
The 200K is high enough to limit the current into the pin protection diode to a safe value even if the voltage exceeds 15V.

Are these "pin protection diodes" internal zenners connecting the pin to ground?

#### retrolefty

#11
##### Dec 14, 2012, 11:36 pmLast Edit: Dec 14, 2012, 11:39 pm by retrolefty Reason: 1

Quote
The 200K is high enough to limit the current into the pin protection diode to a safe value even if the voltage exceeds 15V.

Are these "pin protection diodes" internal zenners connecting the pin to ground?

No they are two simple PN diodes wired from the pin to ground and pin to Vcc inside the chip. If pin voltage goes higher then Vcc or more negative then ground (plus diode Vf rating) the diode conducts thus protecting the chip from 'seeing' higher then Vcc +.6 or lower then -.6 voltage. However if the current flow through a conducting clamping diode isn't limited by external source resistance then the diode will soon burn open once current exceeds it's maximum rated forward current (perhaps just a 1ma rating typically) and then the chip will 'see' the excessive voltage and be destroyed. Therefore with enough series resistance one could even apply 120vac to a input pin with no damage to the pin, but we are talking well over 100K ohms of series resistance required to prevent damage to the clamping diodes.

Lefty

#### lemming

#12
##### Dec 14, 2012, 11:58 pm
Thanks Retrolefty. That clarifies it.

#### krupski

#13
##### Dec 15, 2012, 01:07 am

But the Arduino analog input pins really wants to see a source impedance of 10k ohms or less for best results. He may have to take multiple analog reading and average the results if working with higher resistances.

Lefty

Agreed. And since the OP is measuring a lead-acid battery, you know there are lots of amp-hours available... even a "stiff" resistive divider won't mean a thing to it.

An external diode to clamp the input from going above the AVR VCC voltage might be a good idea - I wouldn't want to put that kind of stress on the internal clamping diodes (if there are any).
Gentlemen may prefer Blondes, but Real Men prefer Redheads!

#### retrolefty

#14
##### Dec 15, 2012, 02:05 am
Quote
An external diode to clamp the input from going above the AVR VCC voltage might be a good idea - I wouldn't want to put that kind of stress on the internal clamping diodes (if there are any).

Sure a one amp diode and a series say 100 ohm resistor between the analog pin and the junction of the voltage divider would make it pretty bullet proof.

Lefty

Go Up