By Kevin McAleer, 6 Minutes
Page last updated November 24, 2026

By the end of this lesson you will be able to respect the Pico’s 3.3 V and current limits, and read a voltage divider with the ADC.
Everything so far has run from a battery. Now we bring in the brain. The Pico can read voltages and switch pins, but it has rules: voltage levels, current limits and a particular way of reading analog values. In this lesson we learn them, and then read our LDR divider with the Pico’s ADC.
The Pico’s pins work at 3.3 V. A pin outputting a 1 sits at 3.3 V, and 0 sits at 0 V. As an input, anything above about 2 V reads as 1, and anything below about 0.8 V reads as 0. In between the pin is undefined, so avoid it.
Never apply more than 3.3 V to a GPIO pin. The pins are not 5 V tolerant. If you have a 5 V sensor output, use a voltage divider (lesson 8!) or a level shifter to bring it down. For example, a 1k resistor on top and a 2k at the bottom turn a 5 V signal into about 3.3 V (5 x 2 / 3 = 3.33 V). This only works for a signal going into the Pico, not for powering things.
A GPIO pin is not a power supply. By default each pin can drive about 4 mA comfortably, and can be set up to about 12 mA, with an overall limit for the whole chip. As a rule: keep each pin to a few milliamps and use a transistor for anything bigger. That is exactly why our night light’s LED goes through a transistor, with the pin driving only the 2.6 mA base current from lesson 11.
From light in the room to a number in your code:
flowchart LR
A["Light on the LDR"] --> B["Divider output<br>0 to 3.3 V"]
B --> C["ADC pin GP26"]
C --> D["read_u16<br>0 to 65535"]
D --> E["volts = raw / 65535 x 3.3"]
The Pico has an ADC (analog to digital converter) that turns a voltage into a number. Three pins can do it:
The ADC is 12-bit, so it has 4096 steps from 0 V to 3.3 V. MicroPython’s read_u16() scales that to 0 to 65535, so your code is the same on every board. The conversion is:
voltage = reading / 65535 x 3.3
Neat detail: the ADC has its own reference and ground, ADC_VREF (physical pin 35) and AGND (physical pin 33). For the best accuracy, use AGND for sensor grounds when you can.
Wire a 10k pot: one outer pin to 3V3(OUT) (physical pin 36), the other outer pin to GND (physical pin 38), and the wiper to GP26 (physical pin 31).
# MicroPython on the Pico
# Read a voltage divider on GP26 (ADC0) and print it
from machine import ADC
from time import sleep
sensor = ADC(26) # GP26 = ADC0
while True:
raw = sensor.read_u16() # 0 to 65535
volts = raw / 65535 * 3.3
print(f"raw={raw:>5} volts={volts:.2f}")
sleep(0.25)
Turn the knob and watch it sweep from 0.00 to about 3.30. Seeing the voltage you measured with your multimeter appear on screen is a real moment: the circuit and the code are talking.
Analog readings wobble a little. Average several samples for a calmer number:
# MicroPython on the Pico
# Average 16 ADC samples to reduce noise
from machine import ADC
from time import sleep_ms
sensor = ADC(26)
def read_volts(samples=16):
total = 0
for _ in range(samples):
total += sensor.read_u16()
return total / samples / 65535 * 3.3
while True:
print(f"{read_volts():.2f} V")
sleep_ms(250)
Replace the pot with the LDR divider from lesson 8: 3V3(OUT) to LDR, LDR to the junction, junction to the 10k, 10k to GND, and from the junction a wire to GP26. Run the same program. Cover the LDR and the number drops. Shine your phone torch on it and it climbs. That is the sensor stage of the night light, working.
Why this matters: every analog sensor, from a battery monitor to a line follower, uses this same read-volts pattern.
Common mistakes:
Teachers: a wrong wire can feed the Pico more than 3.3 V on a pin, so make 3V3(OUT) the only supply for the divider and have learners show you the wiring before plugging in the USB cable. Thonny works on most school machines, but installing it or the Pico drivers may need an administrator, so check this before the lesson.
Why: A loose connection leaves the pin floating, which picks up noise.
Quick quiz 1 of 3
Which pins can read an analogue voltage on the Pico?
Quick quiz 2 of 3
What does read_u16() return for 3.3 V at the pin?
Quick quiz 3 of 3
You have a 5 V sensor output. What do you do before connecting it to a GPIO pin?
Comments