Counts and volts
analogRead does not return volts. It returns a count: how many steps of the ADC's range the pin's voltage reaches. An Uno has 1024 steps across 5 V, the 3.3 V boards 4096 across 3.3 V, and the ESP32's range stops short of the top.
A count, not a voltage
An analog-to-digital converter, the ADC, compares the voltage on a pin with its own full range and returns how far up that range it is, as a whole number. Zero volts is 0. The top of the range is the largest number it can give.
Two ranges, two sizes of step
The Uno's ADC has 10 bits, so it counts from 0 to 1023, and its range is its own 5 V supply. One count is about 4.9 mV. To turn a reading back into volts, multiply by 5.0 and divide by 1023.
The ESP32, the ESP32-S3 and the Pico have 12-bit ADCs, 0 to 4095, over a
3.3 V range: about 0.8 mV a count. The Pico's Arduino core starts out at 10
bits to match the Uno, which is why every sketch in this book calls
analogReadResolution(12).
Because VCC is the top of the knob's range and the ADC's range too, the same turn gives the same fraction of full scale on every board. Halfway is about 512 on an Uno and about 2048 on a Pico. The counts differ; the fraction does not.
Where the ESP32 falls short
The ESP32 and ESP32-S3 do not measure all the way to 3.3 V. At the setting the Arduino core uses by default, the range runs roughly from 0 to 3.1 V, and the readings bend near both ends of it. Everything above the ceiling reads 4095, so the last part of the knob's turn reads the same number.
Pick the ESP32 in the figure and slide the voltage to the top to see it. The block is fine and so is the chip: the range simply does not reach VCC. Calibrating the turn measures where yours actually stops, which is better than assuming.
What a count is worth
For a knob, a count is far finer than a hand. Even an Uno's 1024 steps are more than anyone can set on purpose, and on the 12-bit boards the last few counts are noise rather than position. Smoothing the reading takes that jitter out without making the knob feel slow.
When it does not work
Finer, not necessarily more accurate. A 12-bit ADC has steps of about 0.8 mV, but its readings also wander by several counts and are not perfectly straight, especially on an ESP32. For a knob, 1024 steps is already more than a hand can set.
The arduino-pico core's analogRead starts at 10 bits, like an Uno's, for compatibility. The book's sketches call analogReadResolution(12) in setup, which gives the Pico's full 12 bits. Without it, the numbers are a quarter as large and still correct.
Expected. At the Arduino core's default setting its ADC reads roughly 0 to 3.1 V, not 0 to 3.3 V, and bends near both ends. Dividing by 4095 and multiplying by 3.3 is an approximation. analogReadMilliVolts() uses the chip's own calibration and is closer.
The Uno's reference can be changed with analogReference, including to an external voltage on its AREF pin, which spreads 1024 steps across a smaller range. Read the Uno's documentation for the AREF rules before you try: a wrong setting can short the internal reference.
Edit this page — content/books/rotary-potentiometer/counts-and-volts.mdx
Questions about this product
See what other owners have asked, and read their solutions.
Rotary Potentiometer
Loading discussions…
Discuss this article
Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.