ADC Measurement & Reference Error

ReviewedIntermediate MakerAbout 5 min
ESP32
In short

ADC Measurement & Reference Error: the short answer

An ADC turns a voltage into a number. The number of steps depends on its resolution: 10 bits gives 0 to 1023 (Arduino Uno), 12 bits gives 0 to 4095 (ESP32).

Level
Intermediate
Time
About 5 min
Topic
Microcontrollers
You will learn to

Convert ADC readings to volts and know what makes them inaccurate.

Before this: Voltage, Current & Resistance, Arduino and ESP32 Basics

An ADC turns a voltage into a number. The number of steps depends on its resolution: 10 bits gives 0 to 1023 (Arduino Uno), 12 bits gives 0 to 4095 (ESP32).

To convert back to volts: volts = reading ÷ max × reference. On an Uno the reference is 5 V, so each step is about 4.9 mV. If your USB supply is really 4.8 V, every reading is off by 4 %, because the reference moved.

The ESP32's ADC is less linear near its ends, especially below about 0.1 V and above about 3.1 V. Use analogReadMilliVolts() for calibrated values, and keep signals in the middle of the range when you can.

Noise is normal. Take several readings and average them, and add a 100 nF capacitor from the pin to ground for slow signals like a potentiometer or soil sensor.

Resolution is not accuracy

A 12-bit ADC reports 4,096 steps, but that says nothing about whether the number is right. Offset, gain error, nonlinearity and noise all add up. On an ESP32, the effective number of useful bits is closer to 9 or 10. Think of the last two or three bits as noise unless you average.

Accuracy comes from a good reference, a clean layout and calibration. If you need a precise number, an external ADC such as the ADS1115 (16 bits, with a stable reference) gives far better results than the built-in one.

The reference decides everything

The ADC compares the input with a reference. If the reference is the supply, any change in supply shows up as a change in reading. An Uno powered from USB at 4.8 V reads 4 % wrong if you assume 5 V. Fixes: use the internal reference (about 1.1 V on an Uno), use an external reference chip, or measure the real supply and correct for it.

For a battery-powered ESP32, the supply falls as the battery drains, but its ADC uses an internal reference, so readings stay consistent.

Source impedance and sampling

The ADC has a small sampling capacitor that must charge from the input within microseconds. A high-resistance source, such as a 100 kΩ divider, cannot charge it in time, and the reading is low and drifts with the previous channel. Keep the source resistance under about 10 kΩ, or add a 100 nF capacitor from the pin to ground to supply the charge. Take a dummy reading after switching channels.

Sample often and average, or use a median filter to remove spikes. An exponential moving average (new = 0.9 × old + 0.1 × reading) needs almost no memory.

Using sensors with ADCs

Match the sensor's output range to the ADC's input range: a 0 to 5 V output cannot go into a 3.3 V ADC without a divider, and a tiny signal such as a thermocouple needs an amplifier. Keep analog wires short, away from switching lines, and join analog ground at one point. On an ESP32, avoid the ADC2 pins when Wi-Fi is on.

Common mistakes
  • Treating the 12th bit as meaningful without any averaging.
  • Assuming a USB-powered reference is exactly 5 V.
  • Reading a high-impedance sensor directly with no buffer or capacitor.
Key formulas
code = Vin ÷ Vref × (2ⁿ − 1)
ADC reading for n bits
step = Vref ÷ 2ⁿ
smallest change it can see
Try it: ADC steps

Reading against input voltage

0 5 10 15 0 V1 V2 V3 VInput

An ADC turns a voltage into a whole number. More bits means smaller steps.

16 steps of 206 mV each

Reading against input. Each flat step is one count. The width of a step is the smallest change it can see.

Work it with your own numbers: ADC conversion

Intermediate lesson · Maker plan

Practise this lesson with Maker

The explanation above is free for everyone. The practice for Intermediate lessons in every domain are part of the Maker plan at ₹499 a month, and Pro includes them too.

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

Common questions

What will I learn in "ADC Measurement & Reference Error"?

Convert ADC readings to volts and know what makes them inaccurate.