Wiring guide

How to wire a potentiometer to a Raspberry Pi Pico

To wire a potentiometer to a Raspberry Pi Pico, connect 1 to 3V3(OUT), 2 to GP26 (physical pin 31) and 3 to GND. Run the pot from 3.3 V, never from the 5 V pin, so the wiper can never put more than 3.3 V on an analog input. The sketch below uses no library beyond what the board includes. It reads the wiper and prints the raw reading and a percentage.

  • 3.3 V logic
  • Library: none
  • 3 wires
Raspberry Pi Pico · potentiometerlive0.000 s 0.00x
Click to open it in the editor
The circuit itself, running on the simulator with the sketch below. Press what can be pressed; click anything else to open it in the editor.
Pin to pin

Potentiometer to Raspberry Pi Pico wiring table

Every wire in the circuit above, with the part’s pin names and the board’s own labels. The wire colors are the ones the circuit uses; on a real bench any colors work.

Potentiometer pinRaspberry Pi Pico pinWire colorWhy
Pin 1 (one end)3V3(OUT)redThe top of the ADC’s range is 3.3 V, so the pot spans 0 to 3.3 V.
Pin 2 (wiper)GP26 (physical pin 31)amberThe middle leg: a voltage between the two ends, set by the shaft.
Pin 3 (other end)GNDblueThe bottom of the range.
Voltage

Power and logic levels for potentiometer and Raspberry Pi Pico

Logic level

The Raspberry Pi Pico’s GPIO pins are 3.3 V logic and are not 5 V tolerant. Nothing wired to a pin may go above 3.3 V.

Supply

The potentiometer takes 3.3 V from 3V3(OUT). That pin is the Raspberry Pi Pico’s own regulated 3.3 V output.

This pair

Run the pot from 3V3, never from VBUS (5 V from USB): turned to the top, the wiper would put 5 V on an analog input rated for 3.3 V. GP26 to GP28 are the ADC inputs (A0 to A2): the converter is twelve bits against the 3.3 V rail, and analogRead() returns ten bits, 0 to 1023, as arduino-pico does; analogReadResolution(12) gives 0 to 4095.

Pins to leave alone

The numbers in the code are GP numbers, not the physical pin numbers printed beside the header: GP15 is pin 20. GP23 to GP25 are used on the board itself, and GP25 is the LED.

The sketch

The working code for the Raspberry Pi Pico

Library: none, the sketch reads the wiper with analogRead(). This is the sketch the circuit above runs.

Reading a potentiometer on Raspberry Pi Pico GP26 (physical pin 31)
const int POT_PIN = 26;   // the wiper, GP26 (physical pin 31)

void setup() {
  Serial.begin(115200);
}

void loop() {
  int raw = analogRead(POT_PIN);            // 0 to 1023
  int percent = map(raw, 0, 1023, 0, 100);
  Serial.print("Raw: ");
  Serial.print(raw);
  Serial.print("  Percent: ");
  Serial.println(percent);
  delay(200);
}
Output

What you should see

Open the serial monitor at 115200 baud and turn the knob: each line shows the raw reading and a percentage that follow it. GP26 to GP28 are the ADC inputs (A0 to A2): the converter is twelve bits against the 3.3 V rail, and analogRead() returns ten bits, 0 to 1023, as arduino-pico does; analogReadResolution(12) gives 0 to 4095.

A reading that jumps around or stays at zero means the wiper is not on the analog pin, or the outer legs are not on power and ground.

The serial monitor prints this, recorded from the circuit above with the knob at its middle:

Raw: 511  Percent: 49
Pitfalls

Common mistakes wiring a potentiometer to a Raspberry Pi Pico

Reading a digital pin

analogRead() needs one of A0 to A5. On a digital pin it reads nothing useful.

Wiring the wiper to an end

The middle leg is the wiper. With an end leg on the analog pin the reading never moves, or jumps from 0 to the top at one end of the travel.

Running the pot from VBUS (5 V from USB)

At the top of the travel the pin would see 5 V, above the RP2040’s rating. The pot belongs on 3V3.

Build your own potentiometer project

Open this circuit in the editor, change the wiring or the code, and keep your version in a free account.