Home › Lessons › Embedded (ESP32) › Monitoring a supply rail with the ADC

Monitoring a supply rail with the ADC

Embedded (ESP32) · Intermediate · about 20 minutes · part of Zen’s Electronics Design Mastery

The ESP32’s ADC reads from about 0.15 V to 3.1 V at its default setting, and is only straight up to about 2.45 V. So a 12 V battery must be scaled down well below 3.3 V: a 100 kΩ / 22 kΩ divider puts 12.6 V at 2.27 V, and a full 14.6 V still only at 2.63 V. The sketch reads calibrated millivolts and multiplies back up. Large resistors barely drain the battery.

Monitoring a supply rail with the ADC: the circuit on the simulator's bench

Open this lesson in the labFree, in your browser, no account needed.

How it works

Vpin = Vbatt × R2/(R1+R2) = 12.6 × 0.1803 = 2.272 V.

Raw analogRead() ≈ 3127 on this board (a straight line would say 2820): don't scale raw counts by 3.3/4095. analogReadMilliVolts() uses the chip's calibration and is good to about ±60 mV up to 2.45 V.

Highest readable battery voltage: about 3.1 V ÷ 0.180 = 17.2 V. Divider drain: 103.3 µA.

Try it on the bench

  1. Turn the battery supply down from 12.6 V to 11 V: the sketch tracks it.
  2. Push it above 17 V: the pin passes 3.1 V and the reading sticks at the top, however high the battery goes.
  3. Change R2 back to 33 kΩ (and the sketch to match): 12.6 V now lands at 3.13 V, past the top of the ADC.

Parts on the bench

In the course

Zen’s Electronics Design Mastery, module “Microcontrollers & Embedded”.

More on embedded (esp32)