A microcontroller thinks in whole numbers. To read a voltage, it uses an analog-to-digital converter (ADC) that turns the voltage into a count.
Key idea
An $n$-bit ADC gives readings from $0$ to $2^n - 1$. A 10-bit ADC (Arduino Uno) reads 0 to 1023; a 12-bit one reads 0 to 4095. Reading $= \dfrac{V}{V_{\text{ref}}} \times (2^n - 1)$, rounded. The Pico's ADC returns 0 to 65535 in MicroPython, scaled up from 12 bits.
Why it works
Knowing the size of one step tells you how fine your measurement can be. With 10 bits and 5 V, one count is about 4.9 mV. Noise smaller than that is invisible; noise bigger shows up as a jumpy reading.
Worked example: Voltage to count
A 10-bit ADC with $V_{\text{ref}} = 5\ \text{V}$ reads 2.0 V.
- $\dfrac{2.0}{5} \times 1023 = 409.2$.
- Rounded: 409.
Answer: 409.
Worked example: Count to voltage
A 12-bit ADC with $V_{\text{ref}} = 3.3\ \text{V}$ reads 3000.
- $V = \dfrac{3000}{4095} \times 3.3 \approx 2.42\ \text{V}$.
Answer: About 2.42 V.
Common mistake
Using 1024 or 4096 as the top reading. The largest reading is one less, because counting starts at 0.
Safety for your board. Never put more than the board's own supply voltage on an input pin. A Pico and many newer boards run at 3.3 V, and 5 V on a pin can damage them.