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
- Quantization turns continuous voltage into discrete codes
- Noise can dominate; averaging reduces noise at the cost of responsiveness
- On ESP32: prefer ADC1 when using Wi‑Fi
- Attenuation changes measurable voltage range (Vfs)
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.