Help with battery monitor circuit

Hi,

First off, I just want to let you know that I'm no electronics engineer, and that's why I'm posting this. Here's what I want do do:

I would like to be able to monitor the voltage of a battery pack connected to my Arduino Diecimila when it's not powered via USB. That way, it could alert me or go to sleep or something when it is about to run out of juice.

After searching around, I've found two possible options:

The former, with a couple lines of Arduino code, would give me a percentage of battery remaining (I think) (example: "Warning: battery is at 25% of 9V").

The latter, with the correct circuit, could be read with a digital input (high for low battery, low for battery ok). The problem is, I don't know how to design a correct circuit for it.

Any help would be greatly appreciated. Which approach would be better, and how would I go about implementing it in hardware? Thanks in advance!

are you sure you cant get an analog analizer of the voltage? becuase an analog input would give you very easy numbers and commands to work with...

What do you mean? Is an analog analyzer a part/circuit or something that would allow me to read the voltage from an analog input?

yea, like the voltage sensors you were talking about, except they can go in the arduino analog input instead of digital input, becuase then you have MUCH more flexability with numbers, instead of just low and high...

but i dont know what kind of voltage sensors are out there...

That's great and all, but I need to know things like manufacturers or part numbers!

Does anyone know how to design circuits for the MAX8211?

You can build a voltage divider (two resistors) to measure the battery voltage with the Arduino's built-in ADC.

Datasheets are wonderful things - if you are interested in an IC, get the data sheet. They nearly always include a reference design or example circuit to show how it is used.

Maxim is a good place to find data about Maxim ICs (e.g. part numbers that start with MAX).

-j

Thanks for the reply!

I did get the datasheet for the 8211, but I'm still having trouble understanding it. There are multiple examples, and all the circuit design terms confuse me :frowning:

I also found some Maxim "fuel gauge" battery monitors, which give estimated remaining charge in % and mAh. They looked perfect for what I want, but they're only available in surface-mount packages, not DIPs like the MAX8211.

The voltage divider and analog-in approach seems more desirable, because it's an analog reading, not just a 1 or 0. I would probably have the Arduino-powered device send it's battery voltage via serial to a computer, which would log the voltages until the thing dies (one-time calibration). Then, that value would help the Arduino know when it is going to run out of power.

kg4wsv, does that sound good? I'll look into the voltage-divider thing. Thanks!

http://www.uoguelph.ca/~antoon/gadgets/shunts/shunts.html

This can be used with proper scaling to measure current over time. You can read the voltage, properly scaled with another analog pin.

If you know that and you told the arduino when the battery was charged you can get an idea of how much power is left. If you don't trust your battery maker (HAHAHAHA) you would use the arduino to measure how much current is used until voltage falls below a certain level and to record that for you when you ask for it. Using those figures you can set up the values you need for your announcements.

The voltage divider and analog-in approach seems more desirable, because it's an analog reading, not just a 1 or 0. I would probably have the Arduino-powered device send it's battery voltage via serial to a computer, which would log the voltages until the thing dies (one-time calibration). Then, that value would help the Arduino know when it is going to run out of power.

A voltage divider is nice and simple way to implement a battery meter. It won't tell you how much life is left in the battery but the voltage can provide a serviceable indication of the battery state.

There is lots of info on voltage dividers on the net. In this example http://www.staff.cofa.unsw.edu.au/~bradmiller/physical_computing/analog_io.html, two 4.7k fixed resistors should be used instead of the resistors shown and the +5v will actually be the +9v from the battery.

The Arduino code below uses integer math (floating point consumes lots of memory).

Notes:
The battery voltage on the divider ranges from 0 to 10 volts.
The voltage on the arduino pin ranges from 0 to 5 volts (assuming two 4.7k resistors)
So an analogRead value of 1024 = 10 volts on the divider
Therefore one bit is equal to 10v divided by 1024

// function to print the voltage on the given pin to the serial port
// the pin should be an analog port that has two 4.7k resistors
//    connected as a voltage divider to a 9 volt battery 
// CAUTION, the voltage on the pin must not exceed 5 volts 
void printVolts(int Pin) {
  int value = analogRead(Pin);   
  Serial.print("voltage is: ");
  Serial.print(value / 102,DEC);     // print the integer value of volts
  Serial.print(".");                 // decimal point  
  Serial.println(value % 102,DEC); // hundredths of a volt
}

Yeah, sometimes the downside to data sheets is information overload.

If you look at the first page, you'll see a figure labeled "typical operating circuit (see figure 5)". Then on page 5, you get another copy of that schematic, along with a section on calculating the values of R1, R2, and R3 for your application.

The problem with measuring battery life is that it isn't a linear function. Voltage drops over time, but the shape of that curve varies with battery chemistry.

-j

Thank you all for your advice! ::slight_smile:

One last thing-- some of these examples measure voltage, and some measure current. Which would be more important in regards to battery life and warning of power starvation, for lack of a better term?

That depends on the load and the battery chemistry - I don't know of a formula to give that information. I'd do a bit of measuring while your device consumes a set of batteries to get an idea.

-j