By Kevin McAleer, 3 Minutes

By the end of this lesson you will be able to wire a potentiometer to an ADC pin and use its position as an input.
A potentiometer (or “pot”) is a knob that gives you a voltage you can change by hand. It’s the perfect first analog input. In this lesson you’ll wire one up and read it.
Potentiometers are three-terminal resistors with a sliding contact that forms a variable voltage divider. Turn the knob and the middle pin’s voltage moves smoothly between the voltages on the two outer pins. You can learn more about how potentiometers work here.
3V3(OUT) (physical pin 36)GND (or AGND, physical pin 33, for the cleanest readings)GP26 (physical pin 31)A 10kΩ potentiometer is a good choice.
from machine import ADC
from time import sleep
pot = ADC(26)
while True:
value = pot.read_u16()
percent = value * 100 // 65535
print(value, f"{percent}%")
sleep(0.1)
Turn the knob and watch the numbers change. Thonny’s View > Plotter draws them as a graph.
ESP32 code won’t work here
Examples for the ESP32 use
adc.atten()andadc.read(). The Pico doesn’t have these: useread_u16().
| Potentiometer pin | Connects to |
|---|---|
| Outer pin 1 | 3V3(OUT), physical pin 36 |
| Middle pin (wiper) | GP26, physical pin 31 |
| Outer pin 2 | AGND, physical pin 33 |
pot.read_u16() straight to led.duty_u16() on a PWM pin.Why: The outer pins are fixed at 3V3 and GND, so reading one gives a steady extreme.
Quick quiz 1 of 3
Which potentiometer pin goes to the ADC input?
Quick quiz 2 of 3
What is the potentiometer’s middle pin called?
Quick quiz 3 of 3
Swapping the two outer pins does what?
Comments