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.

  • 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

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.

| improve this answer | |

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