With a picaxe or arduino. Best answer gets a cookie. OK, Go!
I know, it’s not the best…
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)
Well, the ‘best’ method will
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.
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 =)
THX
Sweet action. Calculon thanks you.