How to work out an ADC code and its resolution
An ADC chops the range into equal steps. The code says which step your voltage landed in.
Code = floor(Vin × 2^N / Vref), capped at 2^N − 1 (as in the ATmega328P and ESP32 data sheets)
Result
- Ideal code
- 2,048
- Lsb (approx.)
- 805.7 µV
- Full scale code
- 4,095
- Code back to
- 1.65 V
What this leaves out
- Idealized unipolar converter; input ranges, INL/DNL, attenuation and reference errors vary by device.
Step by step
The working with your numbers
- Number of steps
2^12 = 4,096 - Size of one step (1 LSB)
LSB = Vref ÷ 2^N = 3.3 ÷ 4,096 = 806 µV - The code
code = floor(Vin ÷ LSB) = floor(1.65 ÷ 0.000806) = 2048The highest code is 2^N − 1, so a full-scale input reads one step short. - Voltage that code stands for
2048 × 806 µV = 1.65 VThe real input is somewhere from 1.65 V up to 1.65 V. - Quantisation error
±½ LSB = ±403 µV (0.0122 % of full scale)
Does the answer make sense?
- OK: The input is inside the 0 to 3.3 V range.
- OK: Each extra bit halves the step: 12 bits gives 806 µV, 14 bits gives 201 µV. Noise on a real board usually costs 1 to 3 bits.
Pick a real part
- On an Arduino Uno (10 bits, 5 V) one step is 4.88 mV. An ESP32 (12 bits, 3.3 V) is nonlinear near the ends, so avoid below about 0.1 V and above about 3.1 V.
- To use a bigger step count, pick a 16-bit ADS1115 (50.4 µV per step at 3.3 V) and a clean reference.
Common mistakes
- Dividing by 2^N − 1 instead of 2^N. The usual formula uses 2^N.
- Assuming the ADC is as accurate as it is precise. Offset, gain error and noise matter more than the step size.
- Reading a divided battery voltage and forgetting to multiply back by the divider ratio.
Learn it, try it, build it
Calculated, not measured. Check the exact part datasheet and your real circuit before powering anything.
Just need the number? Use the ideal ADC code / voltage calculator on Geekobot.
Common questions
How do you work out an ADC reading?
code = floor(Vin × 2^N ÷ Vref). For 1.65 V on a 12-bit ADC with a 3.3 V reference: 1.65 × 4096 ÷ 3.3 = 2048.
What is 1 LSB?
The voltage step of one code, Vref ÷ 2^N. A 10-bit ADC on a 5 V reference has an LSB of about 4.9 mV.
