← all lessons
Microcontrollers · #10 of 20

ADC Reading

Quantization, Noise, Averaging

Why it matters

Sensors are analog. The ADC is how your ESP32 reads knobs, light, temperature, battery voltage, and more.

The idea

The core idea

An ADC converts a voltage into an integer code. More bits → smaller steps, but noise can still dominate.
        <div class=

Demo

Gray is the underlying analog signal. Orange is the quantized ADC result. Green is a moving-average filter.

Reduce bits to see bigger steps. Increase noise to see jitter. Increase averaging to smooth jitter. Change attenuation to change full-scale range (Vfs).

Key takeaways

Going deeper

Real ESP32 ADC readings can be non-linear, especially at high attenuation. For better results: use calibration (if available), limit input impedance, and average multiple samples. For battery sensing, use a divider and keep max voltage below 3.3V (and within chosen attenuation range).

Math details

Let Vfs be full-scale voltage and N be bits:
  levels = 2^N - 1
  code = round( (V / Vfs) * levels )
  V_quantized = (code / levels) * Vfs

Quantization error (ideal) is about ±0.5 LSB.

Implementation

LLM Prompt: ADC Reading