Pages: [1] 2   Go Down
Author Topic: measuring battery voltage  (Read 1621 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Sr. Member
****
Karma: 0
Posts: 403
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6619
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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.

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Dubuque, Iowa, USA
Offline Offline
Faraday Member
**
Karma: 47
Posts: 2523
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6619
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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.

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

SW Scotland
Offline Offline
Edison Member
*
Karma: 17
Posts: 1391
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 159
Posts: 2916
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Back to the source of it all,

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

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 159
Posts: 2916
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Are you sure about that?

10k is the magic number.

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

Logged

Australia
Offline Offline
Sr. Member
****
Karma: 13
Posts: 446
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: December 14, 2012, 05:39:22 pm by retrolefty » Logged

Australia
Offline Offline
Sr. Member
****
Karma: 13
Posts: 446
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Retrolefty. That clarifies it.
Logged

Worst state in America
Offline Offline
God Member
*****
Karma: 32
Posts: 799
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Gentlemen may prefer Blondes, but Real Men prefer Redheads!

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1] 2   Go Up
Jump to: