I setup an Arduino Uno to measure a 9V battery's voltage along with a sense voltage to monitor the current leaving the battery through a 10 Ohm sense resistor.
current sink from a previous project and set it to 100mA. I chose 100mA, because my Protostack Arduino Clone with LCD draws roughly 92mA from its DC input and the goal is to have this board estimate the battery capacity left based the 9V battery's measured voltage.
Arduino RTC project. This RTC will come in handy and allow me to reference my measured voltages to a given time on the DS1307.
A little bit of hot glue acts as a strain-relief on the AN0, AN1 and GND wires.
The software is pretty straight forward. I grab the ADC counts read by AN0 & AN1 and then convert the counts to a voltage. I then have to scale the voltage based on the 220K & 100K Ohm resistor divider. After that I grab the Date and Time from the DS1307 RTC and print everything out the comport at 9600 baud. Then I wait a fixed length of time (1 second) and repeat everything,
My full sketch can be found here.
Below is my main loop routine:
// read the analog in value:
BatteryValue = analogRead(BatteryPin);
SenseValue = analogRead(SensePin);
// convert the 0-1023 ADC value to a voltage (Note: 5V reference)
BatteryValue = BatteryValue/1023 * 5;
SenseValue = SenseValue/1023 * 5;
// Compensate the Voltage for the external Resistor divider
// (220K series, 100K shunt) in front of the AN0-1 pins
BatteryValue = BatteryValue / 0.315;
SenseValue = SenseValue / 0.315;
CurrentValue = (BatteryValue - SenseValue) / SenseResistor;
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
// print the results to the serial monitor:
delay(60000); // 1 min Delay
The sketch outputs all the data in a nice table format out the comport and into Hyper Terminal or your other favorite Terminal application:
To be continued...... Next I'll be writing a sketch to display hours left on the 9V battery powering my ProtoStack Arduino Clone.
Part II here: http://embeddederic.blogspot.com/2012/01/arduino-battery-monitor-part-ii.html