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

PartValue / TypeQuantity
Quad comparator U1LM339 with 14-pin socket1
Shunt reference U2TL431 (TO-92)1
R1 (TL431 bias)1 kilo-ohm1
R2, R3 (sense divider)47 kilo-ohm and 10 kilo-ohm, 1 percent1 each
C1 (sense filter)100 nanofarad1
VR1 to VR4 (thresholds)10 kilo-ohm multi-turn trimmers4
LED resistors1.5 kilo-ohm4
LEDsRed, yellow, green, green4
D1 (reverse protection)1N40071
F1500 mA inline fuse1
Push button (optional)To show the level only when pressed1
Bench supply for calibrationAdjustable 10 to 14 V, such as an LM317 supply1

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 pinFunctionConnection
2Output 1LED1 (red) cathode
1Output 2LED2 (yellow) cathode
14Output 3LED3 (green) cathode
13Output 4LED4 (green) cathode
3VCCAfter D1, with 100 nF to GND
12GNDBattery negative
4, 6, 8, 10Inverting inputs 1 to 4Sense divider node
5, 7, 9, 11Non-inverting inputs 1 to 4VR1 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

  1. Identify the TL431 pins from its datasheet; the TO-92 pin order differs between makers and package variants.
  2. Build the reference and measure about 2.49 to 2.50 V across it.
  3. Build the divider and comparators. Connect the bench supply in place of the battery.
  4. 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.
  5. Sweep the supply slowly from 11 V to 13 V and confirm the LEDs come on in order.
  6. 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.