Let's Make Robots!

Best way to monitor battery level?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Calculon320's picture
Sweet action. Calculon thanks you.
OddBot's picture

Since your processor usually runs off of a regulator and has a stable voltage I just use a voltage divider and an analog input. This will give you up to 10 bit resolution. select the values for your voltage divider so that when you battery voltage is at it highest (such as during recharge) the output of the divider is less than you MPU voltage.

For example, you are running your processor off of a 8.4V rechargeable battery via a 7805 +5V regulator. You want to be able to monitor the battery while charging as well as detecting when it gets flat. Your charger might put out 12V with suitable current limiting. This means that the maximum voltage that could appear across you battery in theory is 12V and below 7.5V is dangerously low as your regulator needs 7.5V minimum for good operation.

I would use an 8.2K resistor between the battery positive terminal and the analog input. Then have a 4.7K resistor from the analog input to the negative terminal of the battery (ground). These values allow a small safety margin. At 12V the voltage on the analog input would be 4.37V. When the battery voltage is at 7.5V the analog input would have 2.73V. Sorry there are no diagrams, my software is not work right now.

 Basically what Captain Obvious said.

 As Telefox pointed out this only works when your MCU voltage is regulated.

 

If your processor is running off of batteries and no regulator then use a resistor and a 2.7V zener diode. The resistor (e.g. 1K) goes from +V of your MCU to the analog input. the zener diode goes from your analog input to ground with it's anode to ground (reverse polarity). This will keep a steady 2.7V on your analog input while your MCU's supply voltage slowly drops. The end result is that the analog input slowly rises as the battery goes flat until the battery voltage reaches the zener diode voltage at which point it reaches maximum value. 

TeleFox's picture

Well, the 'best' method will depend on what batteries you have and how much you care about them. If you've got 4 NiMH cells you might only care about whether or not the total voltage is above or below, say, 4.2V. Or you might want to monitor the voltage output in detail, with 12bit precision. Up to you.
Maxim produces several good battery ICs, but I usually prefer a simpler solution. An LED or two connected in series with a high value resistor can be used to make a threshold switch - you can use a digital input and tweak the resistor as needed, or you can use an analog input and adjust the threshold value via code. You can also use a couple of normal diodes in place of the LED/LEDs, but the best option is to find a nice stable Zener diode of the appropriate voltage (based on what threshold you want).
On a few recent projects I've used some very small LEDs so that I could actually fit the voltage monitor underneath the microcontroller (between the IC socket strips), in what would normally be wasted space.

Vref_Sensor.jpg

Edit: BTW the circuit that CO posted (first link) only really works if you've got a voltage regulator feeding the micro, otherwise the upper limit of the analog reference on the ADC will drop at the same rate as the battery voltage drops, which totally defeats the purpose of the circuit =)

CaptainObvious's picture

I know, it's not the best.. but it's a monitor that might get you on the right direction!

http://www.societyofrobots.com/schematics_batterymonitor.shtml

 

There are some IC's you can get (I don't have a clue which ones, just remember reading about them) that can monitor batterys, which would probably the the *best* way to do it, since they are built for. (and a quick search brought up this IC, may or may not be useful!:D)

http://datasheets.maxim-ic.com/en/ds/DS2438.pdf