PIC Battery Voltage Tester

Discussion in 'Embedded Systems and Microcontrollers' started by dmarciano, Oct 10, 2007.

  1. dmarciano

    Thread Starter Member

    Oct 10, 2007
    I am currently designer a battery voltage tester using a PIC16F818. I plan on running the circuit off a 9V battery that is connected to a 7805 to provide 5V to the PIC.

    The batteries that need testing have a maximum voltage of 9V. However since only a maximum of 5V can be applied to any of the PICs pins I have the battery being tested hooked up to a voltage divider which then connects to on of the A/D pins and will compensate for this voltage divide in the source code.

    I was going to connect the PIC in between the two resistors of the voltage divider. Also I was going to have both resistors of the voltage divider to be the same value so the voltage is halved. However since the PIC will be connected in between the two resistors, this will make the PIC and second resistor be in parelle causing the voltage not to be halved. I need to know what the resistance of the PIC pins are so that I can compensate for this extra resistance.

    1. Am I correct that the PIC and R2 would be in parelle cause the voltage not to be halved?

    2. If so, what is the resistance of the PIC so that I can change the values of R1 and R2 so that the voltage of the battery being tested is halved?

    + Test Battery
    |----------------PIC A/D Pin
  2. beenthere

    Retired Moderator

    Apr 20, 2004
    Look at the spec sheet for the PIC and get the input resistance of the A to D input. If it's a couple of orders of magnitude above the value of the resistors in the divider, the loading effect will be negligible. If not, use an op amp as a buffer.
  3. nanovate

    Distinguished Member

    May 7, 2007
    Also look for the max recommended input impedance for the ADC -- usually around 10K -- and make sure R2 is less than this (or use an opamp as a buffer).

    Actually you probably are going to need to buffer since you do not want to have too low value resistor divider and drain your battery.
  4. ASDned

    New Member

    Apr 1, 2009
    Hello there Dmarciano,

    For the resistors value you better can use a 1/3 - 2/3 value so the measure voltage wil be around the 3 volts. Its better to make a switch on top of the resistors witch can be anabled at the time of sampeling. to do this you need to keep in mind not to let a 9 volt get to the pic and there is also a rectifier internal in the chip to the 5 volt so you cannot use it as a pull down! This can be solved by 2 transistors an 2 resistors. On top of the dividing resistors there should be an pnp-transistor with the emitter on the 9 volt and the collector on the divider. The basis is connected with a resistor and then connected to the collector of a npn transistor. The emiter is connected with the ground and the basis to a resistor and then to a output pin of the pic. Now you dont drain your battery because there is only leaking energy when the output is high.

    Best regards and sucses with the hobby.
  5. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    Thought I'd throw in some info I had from manufacturers about Testing Alkaline Batteries, it is rather dated (6 years?), but still applicable.

    Even a dead battery will measure near or above terminal voltage with zero load, such as when measured with a digital multimeter.

    Guidelines from Panasonic and Energizer: Batteries should be measured with a constant current source load on them of roughly 1/3 to 1/6 C, where C is AH/mAH capacity. Battery should not have a load on it for 20 minutes prior to testing. Testing shouldn't take longer than 5 seconds.

    I've included the resistance values, although known current sink is recommended.

    9V Batteries are tested good with an 80Ω load (100mA), typical 9V Capacity is from 400 to 600mAH
    Button Cells - 10mA, 150Ω load.
    AAA run around 700-1200mAH, a 10Ω load (150mA) gives a good indication.
    AA range from 1-2AH, and are tested with a 6Ω load (≈250mA)
    C batteries are tested with 4Ω load (≈375 mA)
    D batteries are tested with a 3Ω load (≈500 mA)

    Button Cells - 10mA, 300Ω load
    Photo Batteries/CR123 - 300mA - 10Ω load, "peak testing" of 0.5C is optional for high draw destinations, such as cameras.

    "Good" > 80% rated voltage (1.2V for 1.5V cells, 7.5V for 9V cells) under load
    "Usable/Low" 1V/cell to 80% rated voltage under load
    "Dead" < 1V/cell under load
    If a battery is still at or above rated terminal voltage with the current sink, a category of "Excellent" may be added.

    A 4.1V Zener and current limiting resistor across the 1.5V input in the event a 9V battery is accidentally connected. 9V input is often a separate "pad" with two conductive pads to hold the battery against long enough to test. This allows uC to catch and display an error without damage.

    Testing methods, automatic and manual:

    Automatic: The uC starts at the lowest current drain, and steps it up rather quickly (1/2 second) until battery reads as "Dead". The battery type can be roughly estimated, and a true "Good/Bad" measurement can be made in under a second. This technique isn't as effective with the variety of lithium, high capacity rechargeable chemistries, and products like "Energizer E2", a user selected type selector is best, using current sinks as loads.

    Simple load: Switches set load resistors to provide drain according to battery type. uC needs to provide an automatic cutoff after 5 seconds to prevent accidental drainage of battery. These are often partially automatic.

    Or, you could simply use a Light bulb with wires on it. :)

    Sorry for the huge post, this is something I needed to design back when.