Measuring battery life remaining with just an analogue in pin

Hi,
simple idea, unlikely to work.

When i test a battery with a multi-meter i measure its voltage, as the battery dies this decreases.

if i connect the battery that is powering my arduino into an analogue in pin as well as vin and ground can i not then estimated battery life remaining for the arduino with this read in value?

thanks

I don't know if your method would work, but the Arduino can measure its own working voltage with this code: Google Code Archive - Long-term storage for Google Code Project Hosting..

That should work just as well as a multimeter. (If it's over 5V, of course, you'll need a voltage divider.)

Batteries don't discharge linearly, but once you get a feel for the discharge pattern of your particular battery in your particular application, you should get useful results.

:smiley: My laptop usually thinks there's 3 hours left right before it dies!

thelonelyprogrammer:
simple idea, unlikely to work.

Correct.

Measuring battery life accurately is difficult, every battery is different.

Battery life remaining isn't overly simple to determine, but it's still a good idea to monitor
battery voltage so you know when the system is about ready to crash. If you're using an
LDO regulator that's known to dropout when Vin gets down to 6V, then when it reads
6.25V, you know it's time to make peace with the world. Save the data to EEPROM,
shutdown activities, and go to sleep.

oric_dan:
Battery life remaining isn't overly simple to determine, but it's still a good idea to monitor
battery voltage so you know when the system is about ready to crash.

To clarify: Knowing remaining battery power is difficult unless you know which battery you're using and have watched it die before (this is how 'smart' laptop batteries work - they store their own discharge curve inside the battery). Even so, if the load is variable (eg. varying hard disk usage) the estimate is only approximate.

Detecting when the battery is actually in the process of dying isn't difficult - the voltage typically drops off very rapidly at the end.

thelonelyprogrammer:
When i test a battery with a multi-meter i measure its voltage, as the battery dies this decreases.

It depends on the battery type. Non-rechargeable alkaline batteries do tend to have a slope in voltage as the battery is drained. Ni-mh/li-po rechargeable batteries tend to deliver the same current for most of the time, until the battery is almost depleted, and then it will start dropping off. Here is a site that discusses the different types of batteries: http://batteryuniversity.com/

I did exactly what you suggest. I know which batteries I use for my project, I drained them once to measure voltage versus total current in mAh, so I can estimate how much juice is left. If you change the batteries you most likely have to make a new curve, but it's better then nothing. I can also display voltage left from my battery pack, most of the time that is my queue to change batteries, in order to keep my LDO working.