PerfBoardSign in

How your ESP32 reads a 12V battery: the voltage divider

Two resistors scale a 12V battery down to a voltage an ESP32's 3.3V input can read safely, with a zener as a backstop.

Component side layout of How your ESP32 reads a 12V battery: the voltage divider on a perfboard 16 by 28 holes
16 × 28 holes · 6 parts · 9 wires

Free build sheet

The parts, every wire with its length and bend points, a bend guide, both sides of the board and checkboxes to track your progress. Print it or keep it open at the bench.

Open the build sheet

What you need

6 parts on a perfboard 16 × 28 holes, plus hookup wire.

QtyPartWhere to buy
1
Ceramic Cap100nF
C1
Buy Ceramic Cap on Amazon
1
Diode (axial)
D1
1
Power Input (2-pin)
J1
1
Signal+Power Header (3-pin)
J2
1
Resistor (axial)39k
R1
Buy Resistor (axial) on Amazon
1
Resistor (axial)10k
R2
Buy Resistor (axial) on Amazon

Check every pin against the datasheet of the exact part in your hands before wiring.

As an Amazon Associate I earn from qualifying purchases.

Cut list

9 wires, 217 mm (8.5 in) in total, in the order the build sheet cuts them. Wire numbers match the build sheet. Each length includes 5 mm per end to go through the hole.

WireColour and netLength
6
BlackGND
E21 → G23
17mm
5
BlueTAP
M21 → H23
28mm
4
GreenTAP
K13 → L20
30mm
1
Red12V
E7 → E5
15mm
7
RedGND
F20 → J15
33mm
3
WhiteTAP
F12 → J12
20mm
9
WhiteGND
I14 → F5
40mm
2
YellowTAP
E13 → E15
15mm
8
YellowGND
K14 → L16
18mm

About this build

A 12V battery is nearly four times what a 3.3V ADC input can survive, so two resistors scale it down: 39k on top, 10k underneath. The tap between them sits at 2.45V, and even with a lead acid pack charging at 14.4V it only reaches 2.94V.

The math is Vout = Vin x 10k / (39k + 10k). A 100nF ceramic on the tap filters the reading, and a 1N4728A 3.3V zener clamps it, so a spike can't push the tap past what the input can take. The tap and ground leave on a 3 pin header.

The zener only works one way round. The build sheet shows which end goes to the tap, and the band on the part tells you which end is which.

More builds

See all builds