Using Potentiometers

Learn how to use potentiometers with the Raspberry Pi Pico and MicroPython.

By Kevin McAleer,    3 Minutes


Course Cover Image


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.

Overview

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.


What are potentiometers?

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.


Connecting a potentiometer to the Pico

  1. Connect one outer pin to 3V3(OUT) (physical pin 36)
  2. Connect the other outer pin to GND (or AGND, physical pin 33, for the cleanest readings)
  3. Connect the middle pin (the wiper) to GP26 (physical pin 31)

A 10kΩ potentiometer is a good choice.


Reading potentiometer values with MicroPython

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() and adc.read(). The Pico doesn’t have these: use read_u16().



Wiring table

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

Try it Yourself

  1. Run the program and turn the knob. Open View > Plotter in Thonny to see it as a graph.
  2. Swap the two outer pins. What changes?
  3. Challenge: use the reading to set an LED’s brightness by passing pot.read_u16() straight to led.duty_u16() on a PWM pin.

Common Issues

  • Problem: The reading jumps between 0 and 65535.
  • Solution: Check the wiper (middle pin) is on GP26, not an outer pin.
  • Why: The outer pins are fixed at 3V3 and GND, so reading one gives a steady extreme.

  • Problem: The reading never reaches the full range.
  • Solution: Check the outer pins really go to 3V3(OUT) and GND.
  • Why: The wiper can only reach the voltages on the outer pins.

Check your understanding

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?


< Previous Next >

Was this lesson helpful?

Course complete

Congratulations, you finished Raspberry Pi Pico with MicroPython - GPIO Mastery!

That's all 18 lessons done. Let people know, it's a great way to inspire someone else to start.

Share card: I completed Raspberry Pi Pico with MicroPython - GPIO Mastery on KevsRobots
Post Bluesky LinkedIn Facebook


What are you looking for?
Watch Videos Get Ideas Learn Something Read a Review Read the Blog Search
... Z Z z