In my last blog post I took an Adruino Uno and a Protoshield and made a simple battery monitor, so I could measure the voltage of a discharging 9V battery when it was drained through a constant 100mA load. Below is the 9V battery discharge curve:
ProtoStack Arduino Clone with LCD draws about 92mA and I wanted to write a sketch to display a battery bar and the approximate hours battery life left. Since all batteries have an internal equivalent series resistance (ESR), it is important to take that into account when only using a battery's voltage to monitor its state of charge. Since we discharged the battery through a load that is similar to the ProtoStack board with LCD, the ESR of the battery has automatically been accounted for in the voltage measurements.
With the plotted excel data from the discharge monitor I created a look-up table in software to approximate the battery life:
Battery Voltage Hours Life Left Displayed Battery Bars
7.87V > Batt 4.5hrs 4
7.45V > Batt <= 7.87V 4.0hrs 4
7.23V > Batt <= 7.45V 3.5hrs 4
7.08V > Batt <= 7.23V 3.0hrs 3
6.94V > Batt <= 7.08V 2.5hrs 3
6.77V > Batt <= 6.94V 2.0hrs 2
6.56V > Batt <= 6.77V 1.5hrs 2
6.30V > Batt <= 6.56V 1.0hrs 1
5.71V > Batt <= 6.30V 0.5hrs 1
Batt <= 5.71V mins left 0
Here is the sketch I wrote: link
I tied the input voltage through a resistor divider (220K Ohm series and 100K Ohm shunt) to the A0 pin on the micro.
link to the spreadsheet I used to calculate the values for the custom characters.
This was a fun project to get myself familiar with the Arduino Analog pins. Now my ProtoStack Board is all ready for a future portable battery powered electronics project.