Accurate ADC Readings: Calibration and Filtering

ReviewedAdvanced ProAbout 6 min
ESP32
In short

Accurate ADC Readings: Calibration and Filtering: the short answer

A microcontroller's ADC rarely gives the accuracy its bit count suggests. 8 V every reading is 4 % off.

Level
Advanced
Time
About 6 min
Topic
Microcontrollers
You will learn to

Get stable, accurate analog readings by calibrating the ADC, oversampling and filtering in firmware, and choosing an external ADC when needed.

Before this: ADC Measurement & Reference Error, Getting Started with the ESP32

A microcontroller's ADC rarely gives the accuracy its bit count suggests. The ESP32's 12-bit ADC is noticeably non-linear and flattens out near the top of its range; the Arduino Uno's 10-bit ADC depends on the 5 V supply as its reference, so if USB gives 4.8 V every reading is 4 % off. Start by understanding your error sources: reference accuracy, gain and offset error, non-linearity, noise and the source resistance of what you are measuring.

Calibrate in the system, not just the chip. On the ESP32, use analogReadMilliVolts() or the esp_adc calibration functions, which apply the factory calibration stored in each chip, and keep the input within the range for your attenuation setting (roughly 150 to 2,450 mV at 11 dB, where the response is best). Then measure two known voltages with a good multimeter, near the bottom and the top of your range, and fit a straight line (gain and offset) to correct the rest. On an AVR, use the internal 1.1 V reference or an external reference such as a TL431 for stable results.

Filter the noise in firmware. Averaging N samples reduces random noise by √N, and oversampling by 4 and shifting adds about one bit of resolution if there is some noise to dither the signal. A moving average or an exponential filter (y = y + α × (x − y), with α around 0.1) smooths slow signals; a median of five rejects single spikes. Add a 100 nF capacitor at the ADC pin when the source resistance is high, so the sampling capacitor can charge. When you need real precision, use an external ADC such as the ADS1115, a 16-bit converter with a programmable-gain amplifier and its own reference.

Know the error sources

An ADC reading has several errors: the reference voltage, offset, gain error, nonlinearity and noise. A 10-bit converter on a 5 V reference has steps of about 4.9 mV, but its real accuracy can be several steps worse, especially on a built-in ADC with a supply as the reference. The ESP32's ADC is known to be non-linear near the ends of its range, so calibrate it against a meter instead of trusting the raw count.

A noisy supply means a noisy reference. Use a stable reference where accuracy matters, and decouple the analogue supply.

Calibrate with known points

Measure two or more known voltages with a good meter, record the ADC counts, and fit a straight line or a short correction table. Two points fix offset and gain. Store the constants, and repeat if the temperature or the supply changes a lot.

Averaging N readings reduces random noise by about the square root of N, so sixteen readings cut it to a quarter. It does not remove an offset or a drift.

Filters and source impedance

A moving average is simple, and an exponential filter, new = old + α × (reading − old), uses almost no memory. A smaller α is smoother but slower. A median of three or five readings removes single spikes without blurring a step. Keep the source impedance low or add a capacitor at the input so the ADC's sampling capacitor charges fully; a high-impedance sensor reads wrongly without a buffer.

Common mistakes
  • Trusting the raw count of a built-in ADC without calibration.
  • Averaging to fix an offset error, which averaging cannot do.
  • Connecting a high-impedance sensor straight to the ADC input.
Advanced lesson · Pro plan

Practise this lesson with Pro

The explanation above is free for everyone. The practice for Advanced lessons in every domain are part of the Pro plan at ₹999 a month.

With Pro you also get: a worked example, a hands-on task, a 3-question check.

Common questions

What will I learn in "Accurate ADC Readings: Calibration and Filtering"?

Get stable, accurate analog readings by calibrating the ADC, oversampling and filtering in firmware, and choosing an external ADC when needed.