12V Battery Level Indicator with LM339 Comparators and TL431 Reference
Inverter batteries, solar storage batteries and bike batteries are all nominal 12 V lead-acid units, and their state of charge can be estimated from the resting terminal voltage. The useful range is narrow, roughly 11.8 V to 12.7 V, so a simple LED-and-resistor tester is useless: it needs to resolve differences of a few hundred millivolts. This project uses an LM339 quad comparator and a TL431 precision shunt reference to light up to four LEDs as a bar graph.
You will learn how to scale a voltage with a divider, why a stable reference matters, and how open-collector comparator outputs drive LEDs.
Components Required
| Part | Value / Type | Quantity |
|---|---|---|
| Quad comparator U1 | LM339 with 14-pin socket | 1 |
| Shunt reference U2 | TL431 (TO-92) | 1 |
| R1 (TL431 bias) | 1 kilo-ohm | 1 |
| R2, R3 (sense divider) | 47 kilo-ohm and 10 kilo-ohm, 1 percent | 1 each |
| C1 (sense filter) | 100 nanofarad | 1 |
| VR1 to VR4 (thresholds) | 10 kilo-ohm multi-turn trimmers | 4 |
| LED resistors | 1.5 kilo-ohm | 4 |
| LEDs | Red, yellow, green, green | 4 |
| D1 (reverse protection) | 1N4007 | 1 |
| F1 | 500 mA inline fuse | 1 |
| Push button (optional) | To show the level only when pressed | 1 |
| Bench supply for calibration | Adjustable 10 to 14 V, such as an LM317 supply | 1 |
Circuit Explained Stage by Stage
Stage 1: Protected supply
The battery feeds the circuit through F1 and D1. The fuse protects the wiring, because a battery can deliver hundreds of amps into a short. D1 blocks current if the clips are reversed. The circuit after D1 runs at about 0.7 V less than the battery, which the LM339 does not mind.
Stage 2: Sense divider
R2 and R3 scale the battery voltage down to about 2 V, taken directly from the battery side of the fuse so that D1's drop does not affect the reading. C1 filters noise. The scaled voltage feeds the inverting input of all four comparators.
V_sense = V_bat x R3 / (R2 + R3) = V_bat x 10 / 57 = V_bat x 0.1754 Threshold V_bat V_sense (set on trimmer wiper) LED1 11.8 V 2.07 V LED2 12.2 V 2.14 V LED3 12.5 V 2.19 V LED4 12.7 V 2.23 V At 14.4 V (charging), V_sense = 2.53 V, inside the LM339 input range
Stage 3: Reference
The TL431 with its reference pin tied to its cathode behaves like a precise 2.495 V zener. R1 supplies it with roughly 9 mA from the 11 to 12 V rail, comfortably above its minimum operating current. Four trimmers in parallel across the reference each produce one threshold at their wipers, which go to the non-inverting inputs.
Stage 4: Comparators and LEDs
Each LM339 output is an open-collector transistor that sinks current when the non-inverting input is below the inverting input. With the battery sense on the inverting input, an output pulls low, and its LED lights, when the battery is above that comparator's threshold. Each LED connects from the supply through a 1.5 kilo-ohm resistor to an output, drawing about 6 to 7 mA.
| LM339 pin | Function | Connection |
|---|---|---|
| 2 | Output 1 | LED1 (red) cathode |
| 1 | Output 2 | LED2 (yellow) cathode |
| 14 | Output 3 | LED3 (green) cathode |
| 13 | Output 4 | LED4 (green) cathode |
| 3 | VCC | After D1, with 100 nF to GND |
| 12 | GND | Battery negative |
| 4, 6, 8, 10 | Inverting inputs 1 to 4 | Sense divider node |
| 5, 7, 9, 11 | Non-inverting inputs 1 to 4 | VR1 to VR4 wipers |
How It Works
Every comparator sees the same scaled battery voltage but a different reference level. As battery voltage rises, the comparators switch on one by one, building a bar from red to green. A well-charged battery that has rested lights all four; a deeply discharged battery lights none.
Assembly and Testing
- Identify the TL431 pins from its datasheet; the TO-92 pin order differs between makers and package variants.
- Build the reference and measure about 2.49 to 2.50 V across it.
- Build the divider and comparators. Connect the bench supply in place of the battery.
- Set the bench supply to 11.8 V and adjust VR1 until LED1 just lights. Repeat at 12.2 V with VR2, 12.5 V with VR3 and 12.7 V with VR4.
- Sweep the supply slowly from 11 V to 13 V and confirm the LEDs come on in order.
- Fit the fuse holder close to the battery clip and mount everything in an insulated box.
Troubleshooting
- LEDs flicker near a threshold: add a little hysteresis with a 1 mega-ohm resistor from each output to its own non-inverting input, or increase C1 to slow down noise.
- All LEDs on regardless of voltage: sense and reference are swapped. The divider must go to the inverting inputs.
- Reference reads 0.7 V or 12 V: the TL431 is inserted with the wrong pin order.
- Readings drift with temperature: use 1 percent metal film resistors and multi-turn trimmers.
- Battery slowly drains: the circuit draws roughly 35 to 40 mA with all LEDs on; use the push button so it runs only on demand.
Summary
A divider scales the battery, a TL431 provides a stable 2.5 V reference, and four LM339 comparators compare the two to build an LED bar graph. Calibrating with a bench supply removes resistor tolerance errors, giving a practical indicator for inverter and solar batteries.