measuring battery voltage

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.

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.

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

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

retrolefty:
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.

dc42:

retrolefty:
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

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

Back to the source of it all,

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/(2piRth*C).

Are you sure about that?

10k is the magic number.

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

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?

lemming:

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

Thanks Retrolefty. That clarifies it.

retrolefty:
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).

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

retrolefty:

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

Yes, an additional resistor in series with the input is a great idea. Even if the external clamp forward drop is a bit higher than the input pin clamp, the resistor will limit the current and prevent a latchup.

The reason I mentioned an external diode is that some microcontrollers have actual clamp diodes on the inputs while others have "pseudo" diodes formed by the junctions of the input FET's. If THOSE are driven above VCC or below ground, the input stage can latch up like an SCR and then the holy smoke is released from the chip and it doesn't work anymore! :slight_smile:

I don't know if the AVR micros have actual clamp diodes on the inputs or not. Better safe than sorry.

From the AVR 328p datasheet:

All I/O pins have protection diodes to both VCC and Ground as indicated in Figure 14-1. Refer to ”Electrical Characteristics” on page 317 for a complete list of parameters.

Lefty

retrolefty:
From the AVR 328p datasheet:

All I/O pins have protection diodes to both VCC and Ground as indicated in Figure 14-1. Refer to ”Electrical Characteristics” on page 317 for a complete list of parameters.

Lefty

OK thanks. I have the PDF file, but I haven't gone through much other than A/D registers, ports and fuses yet. I wish I could get a paper copy (a book). I don't want to print a 567 page document... even double sided!

There is an Atmel application note recommending that the current into the pin protection diodes is limited to no more than 2mA.

dc42:
There is an Atmel application note recommending that the current into the pin protection diodes is limited rated to no more than 2mA.

it's up to the external circuit of course to do the current limiting to stay below the diodes maximum rating. I know you know that, I'm just clarifying for the newbies that tend to treat statements as rules rather then as hints to understanding.

Lefty