I have a robot that uses a Raspberry Pi 3 Model B and a 12 volt sealed lead acid battery. The battery powers other things (motors, etc), and the Pi receives a regulated current.
How can I display the capacity of my battery on the Raspberry Pi as a percentage? I'm looking to the battery indicators on smartphones and laptops as inspiration.

closed as off-topic by Milliways, Patrick Cook, joan, pandalion98, Steve Robillard Feb 11 '17 at 0:45

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be specific to the Raspberry Pi within the scope defined in the help center." – Milliways, Patrick Cook, joan, pandalion98, Steve Robillard
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Have you looked at how the monitoring is done for a smartphone or laptop battery? That will show you why the technique does not apply to a lead acid battery. – joan Jan 19 '17 at 8:49
  • It's not particularly practical to display a real-time readout of the charge remaining on a lead acid battery. You're looking at a minimum of 12 hours of resting time, possibly multiple days depending on temperature, to get sensible baseline readings. Raising the temperature of the battery raises the output voltage and vice versa. For decently accurate measurements you need to use a combination of temperature-compensated specific gravity and voltage, and SG of battery acid is not something I'd like to try measuring in a moving vehicle – goobering Jan 19 '17 at 10:46
up vote 0 down vote accepted

The simplest would be to buy an automotive battery tester (which could be found for as little as $6), and replace LEDs with optocouplers which drive GPIO pins on Raspberry Pi.

A little more complex is to build the circuit from scratch (example), which would require some tuning to get the right values for "high", "meduim" and "low" voltage levels.

Note that if you're talking specifically about the battery in a running car, the task becomes much more challenging. For starters, connecting a permanent circuit directly to the car's battery is a fire hazard, because the voltage you'll see will vary wildly due to the alternator's varying output.

Not the answer you're looking for? Browse other questions tagged or ask your own question.