OTD ACADEMY
Sign in / Sign up
Library

LIBRARYThe ADC: reading an analog voltage.

How an ADC turns a voltage into a number, what resolution and reference voltage set, and how the ESP32's attenuation stretches its range toward 3.3 V. With a divider calculator.

An ADC, for analog-to-digital converter, turns a voltage into a number the program can read. Its resolution sets how finely it splits the range, its reference sets the top of that range, and on the ESP32 an attenuation setting stretches the range toward the 3.3 V rail. A plain GPIO reads only high or low; the ADC reads everything in between.

Resolution: bits become steps

An ADC with N bits splits its input range into two-to-the-N steps. The ESP32's is 12-bit, so it splits the range into 4096 steps. Each step is the smallest voltage change the converter can tell apart, its least-significant bit, or LSB. More bits mean finer steps and a more precise reading.

VLSB=Vref2NV_{LSB} = \frac{V_{ref}}{2^N}

Reference and range

The reference voltage is the input that reads full scale, the very top step. The ESP32's raw ADC range is small (its internal reference is about 1.1 V), so it offers attenuation settings that scale the incoming voltage down first, which extends the usable input range to roughly 0 to 3.1 V at the highest attenuation, close to the rail (ESP32-S3 datasheet, ADC characteristics). Pick the attenuation for the voltage you expect to measure, and the reading uses the whole range instead of a sliver of it.

Scaling a bigger voltage in

To read a voltage above the ADC's range, a battery above the rail for instance, put a voltage divider in front of the input to bring it down into range. The ADC pin draws almost no current, which is exactly the light, high-impedance load a divider needs to hold its ratio. Scale the voltage down by a known fraction, read it, and multiply back in firmware.

Inputs

Result

3.33 V

output voltage (at the tap)

Add an ADC's input impedance in parallel with R2 if it's not much larger than R2.

Quiescent current through the divider

0.167 mA

Scale a higher voltage down into the ESP32's ADC range.
Deep dive· Cleaning up the reading in firmware

The raw number an ADC hands back jitters a little, from electrical noise and the converter's own offset. Two cheap habits fix it. First, average: read the pin several times in a row and take the mean, and the random jitter shrinks. Second, calibrate: measure the known error once against a trusted meter, store it, and correct every future reading. Espressif's ESP-IDF ships an ADC calibration API for exactly this, so the hardware sets the ballpark and a few lines of firmware make it accurate. This is the same averaging idea the voltage-dividers guide uses.

A smooth input voltage being converted into discrete numbered steps by an ADC, with the reference voltage marking the top full-scale step.
A voltage becomes a number: the reference marks full scale, the bits set the step size.

Checkpoint

Quick check

What sets the top of an ADC's input range?
A 12-bit ADC splits its input range into how many steps?
To read a voltage higher than the ADC's range, what do you add in front of it?
0 / 3 correct

One Thousand Drones engineering team · verified 2026-07

ESP32 ADC explained: resolution, reference, and attenuation