Projects / Four-level battery indicator

Four-level battery indicator

Beginner1.5 hGuided buildReviewed

Build it step by step

0 of 8 done
  1. LM339+

    Wire the power

    Battery through the button to the red rail, LM339 pins 3 and 12.

  2. Build the reference

    1 kilohm and the Zener, check about 5.1 V at the node.

  3. Build the ladder

    Four 10k and one 100k to ground.

  4. Wire the plus inputs

    Taps to pins 5, 7, 9 and 11.

  5. Build the sense divider

    Two 10k, centre to pins 4, 6, 8 and 10.

  6. 10.4 mA

    Wire the LEDs

    Resistor from the red rail, cathode to each output pin.

  7. ++

    Press the button

    A fresh battery lights all four.

  8. +10.4 mA

    Try an older battery

    Fewer LEDs light.

In short

How do you build a four-level battery indicator?

A quad comparator, a Zener reference and a resistor ladder light one to four LEDs as a 9 V battery runs down. You need LM339 quad comparator, Zener diode 5.1 V (1N4733A), Resistor 10 kΩ × 6, Resistor 100 kΩ, Resistor 1 kΩ × 5, LED 5 mm red × 2, LED 5 mm green × 2, Tactile push button 6 mm, 9 V battery, 9 V battery snap with DC jack, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points. It takes 8 steps and about 90 minutes.

Level
Beginner
Time
About 90 min
Parts
12

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Battery positivePush button, then the red railPress to test, saves the battery
Battery negativeBlue rail (GND)Common ground
LM339 pin 3 (V+) and pin 12 (GND)Red rail and blue railPower
Red rail1 kilohm resistor to the Zener cathode (banded end)Reference node Z about 5.1 V
Zener anodeBlue railGround
Z10k to T1, 10k to T2, 10k to T3, 10k to T4, then 100k to GNDLadder of four reference taps
T1, T2, T3, T4LM339 pins 5, 7, 9, 11 (the plus inputs)Reference taps
Red rail10k to node S, then 10k to GNDSense node is half the battery voltage
SLM339 pins 4, 6, 8, 10 (the minus inputs)Battery sense
Red rail1 kilohm to each LED anodeOne resistor per LED
LED cathodesLM339 pins 2, 1, 14, 13 (outputs 1 to 4)Output pulls the LED to ground when battery is above the step

Code

A comparator tells you whether one voltage is above another, and four of them with a ladder of reference voltages make a simple level meter. The problem with a battery gauge is that you need a reference that does not fall as the battery does, so this build uses a 5.1 volt Zener diode fed from the battery through 1 kilohm, which holds its voltage while the battery drops from 9.5 to 7 volts. A resistor ladder from that reference gives four taps, from 4.7 to 3.6 volts. The battery itself is cut in half with two 10 kilohm resistors and fed to all four comparators. The LM339 is an open-collector part, so its output can only pull down, not push up, which suits an LED connected from the battery rail through a resistor: the LED lights when the output pulls it to ground. As the battery weakens, the sense voltage drops below the top tap first, then the next, so LEDs go out one by one from the top, which makes a clean bar. With a fresh 9 volt alkaline battery all four should light, half used it will light two or three, and near the end only the red lamp stays lit. A push button saves the battery, because the LEDs draw about 30 milliamps together. Measure your Zener voltage, since it changes all four steps by the same factor, and treat the steps as approximate.

Build notes (no code needed for this build)

How it works: the LM339 has four comparators with open-collector outputs. An output pulls down to ground (low) when its plus input is BELOW its minus input, and floats (off) when the plus input is above.
Here the plus input is a tap on the reference ladder and the minus input is the battery sense. The output is low, and the LED lit, when the sense voltage is ABOVE the tap, so the LED shows the battery is above that step.

Reference: a 5.1 V Zener fed by a 1 kilohm resistor. Ladder: 4 x 10 kilohm resistors then 100 kilohm to ground.
Tap voltage n (with Vz = 5.1 V): T1 = Vz x 130/140 = 4.74 V, T2 = 4.37 V, T3 = 4.00 V, T4 = 3.64 V.
Sense node S is the battery voltage divided by 2 (10k and 10k).
Battery voltage at which each LED lights (calculated): LED 1 about 9.5 V, LED 2 about 8.7 V, LED 3 about 8.0 V, LED 4 about 7.3 V.
LED 1 and LED 2 use the green LEDs (high battery), LED 3 and LED 4 use the red ones (low battery).

If your Zener measures a different voltage (they are 5 percent parts), multiply each battery step by Vz measured divided by 5.1.
With the button pressed the circuit draws about 25 to 40 mA, so only press it briefly.

LM339 pins: 1 out2, 2 out1, 3 V+, 4 in1 minus, 5 in1 plus, 6 in2 minus, 7 in2 plus, 8 in3 minus, 9 in3 plus, 10 in4 minus, 11 in4 plus, 12 GND, 13 out4, 14 out3.

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Zener nodeAbout 5.1 V
Tap voltagesAbout 4.7, 4.4, 4.0 and 3.6 V
Fresh 9 V batteryThree or four LEDs
Half-used batteryTwo LEDs
Weak battery near 7 VOnly the red LEDs, then none

If it does not work

No LED lights

Check the LED direction and the output pins.

All LEDs always on

Check the sense node and that pins 4, 6, 8, 10 are joined.

LEDs light in the wrong order

Check the ladder order of the taps.

Zener node is low

Check the 1 kilohm and the Zener direction.

LEDs very dim

Use 1 kilohm resistors, not larger ones.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the four-level battery indicator?

LM339 quad comparator, Zener diode 5.1 V (1N4733A), Resistor 10 kΩ × 6, Resistor 100 kΩ, Resistor 1 kΩ × 5, LED 5 mm red × 2, LED 5 mm green × 2, Tactile push button 6 mm, 9 V battery, 9 V battery snap with DC jack, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points.

How long does the four-level battery indicator take to build?

About 90 minutes for a beginner maker, in 8 steps.

How do I know the four-level battery indicator works?

Zener node: About 5.1 V. Tap voltages: About 4.7, 4.4, 4.0 and 3.6 V. Fresh 9 V battery: Three or four LEDs.

No LED lights: what should I check?

Check the LED direction and the output pins.

All LEDs always on: what should I check?

Check the sense node and that pins 4, 6, 8, 10 are joined.

LEDs light in the wrong order: what should I check?

Check the ladder order of the taps.

Zener node is low: what should I check?

Check the 1 kilohm and the Zener direction.