5. Measure a voltage
You will be able to
- read a voltage with the Pico's ADC,
- build a voltage divider,
- convert a raw reading into volts or a percentage,
- make a decision with a threshold and with hysteresis.
You need: two 10 kΩ resistors (a divider), or a potentiometer. Problems: Read a voltage, Night light, Sticky dimmer, Bar graph.
The idea
A digital pin reads only 0 or 1. An analogue-to-digital converter (ADC) measures in between.
The Pico's ADC is 12-bit: it turns 0–3.3 V into 0–4095. MicroPython's read_u16() gives a 0–65535 version of the same measurement (16-bit scaling), which is finer than the hardware.

Two equal resistors put half the supply in the middle: 1.65 V. The ADC should read about half its range.
Fun fact. 4096 steps over 3.3 V is about 0.8 mV per step — more than a hundred times finer than the 0.1 V you can read on a cheap multimeter.
The exact tools
| What | MicroPython | Notes |
|---|---|---|
| An ADC pin | ADC(26), ADC(27), ADC(28) | Only GP26–28 |
| 16-bit reading | adc.read_u16() | 0–65535 |
| 12-bit reading | adc.read() | 0–4095 |
| Volts | adc.read_u16() * 3.3 / 65535 | Compare like with like: use volts everywhere |
| Percentage | round(adc.read_u16() * 100 / 65535) | 0–100 |
Build it
from machine import ADC
import utime
adc = ADC(26)
while True:
volts = adc.read_u16() * 3.3 / 65535
print(round(volts, 2))
utime.sleep(0.5)
You should see about 1.65 with the equal divider.
Thresholds and hysteresis
A single threshold makes an output chatter when the input sits near it. Hysteresis uses two thresholds with a gap:
if reading > 0.7 * 65535:
on = True # clearly bright
elif reading < 0.3 * 65535:
on = False # clearly dark
# in between: keep what it was
Think about it. Why is the gap useful for a night light? (The light itself can change the sensor's reading; without a gap the lamp would blink on and off all night.)
What you should see
The printed voltage follows the divider. With a potentiometer, turning the shaft sweeps the number from 0 to about 3.3 V.
Common mistakes
| What you see | Why | Fix |
|---|---|---|
ValueError on ADC(13) | GP13 is not an ADC pin | Use GP26, GP27 or GP28 |
| The reading never changes | The wiper is not connected to the ADC pin | Wiper → GP26 |
| The reading is noise | The input is floating | Add the divider or a pull |
| The reading is pegged at full | More than 3.3 V on the pin | Check the divider; 5 V can damage an ADC pin |
Check yourself
- How many volts is full scale on the ADC?
- What does an equal divider put on GP26?
- Why use 0.3 and 0.7 instead of one threshold?
Answers: 3.3 V · half of 3.3 V, about 1.65 V · the gap stops chatter near the threshold.
Remember
- ADC is only on GP26, GP27, GP28; it measures 0–3.3 V.
read_u16spans 0–65535; convert to volts before comparing.- Two thresholds with a gap = hysteresis.
Go further
- Read a divider and print the voltage — Read a voltage.
- Turn an LED on when it gets dark — Night light.
- Keep the LED on until it is clearly bright — Sticky dimmer.
- Draw the reading as a bar — Bar graph.
Next: Lesson 6 — Dim and move