Raspberry Pi Pico Analog Input: Wiring, Code and Simulator
To build this Raspberry Pi Pico Analog Input project you need a Raspberry Pi Pico and a potentiometer. analogio reads a potentiometer on GP26 and converts it to volts. Make the 3 connections in the wiring table, upload the CircuitPython code, and turn the knob and watch the voltage run from 0 to 3.3 V.
Open this circuit in the free Raspberry Pi Pico simulator
Parts list
| Qty | Part | What it does |
|---|---|---|
| 1 | Raspberry Pi Pico | the microcontroller board |
| 1 | Potentiometer | VCC to 5V, GND to GND, SIG to an analog pin. Drag the knob; analogRead gives 0–1023. |
Wiring
| # | From | To |
|---|---|---|
| 1 | Raspberry Pi Pico GP26 | Potentiometer SIG |
| 2 | Raspberry Pi Pico 3V3 | Potentiometer VCC |
| 3 | Raspberry Pi Pico AGND | Potentiometer GND |
Step by step
- Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Raspberry Pi Pico. No install or account is needed.
- Add the parts. Add a potentiometer from the parts palette.
- Wire 1. Connect Raspberry Pi Pico GP26 to Potentiometer SIG.
- Wire 2. Connect Raspberry Pi Pico 3V3 to Potentiometer VCC.
- Wire 3. Connect Raspberry Pi Pico AGND to Potentiometer GND.
- Paste the CircuitPython code. Paste the CircuitPython code below into the code editor.
- Run it. Press Run. Turn the knob and watch the voltage run from 0 to 3.3 V.
CircuitPython code
# CircuitPython analog input: a potentiometer on GP26, read as 0-65535 and volts.
import board
import analogio
import time
pot = analogio.AnalogIn(board.GP26)
while True:
volts = pot.value * pot.reference_voltage / 65535
print("reading:", pot.value, " volts: {:.2f}".format(volts))
time.sleep(0.25)
What to try
Turn the knob and watch the voltage run from 0 to 3.3 V.
Frequently asked questions
How do I wire the Analog Input project on a Raspberry Pi Pico?
Make 3 connections: Raspberry Pi Pico GP26 to Potentiometer SIG; Raspberry Pi Pico 3V3 to Potentiometer VCC; Raspberry Pi Pico AGND to Potentiometer GND.
What parts do I need for this Raspberry Pi Pico project?
A Raspberry Pi Pico and a potentiometer.
Can I simulate this Raspberry Pi Pico project online for free?
Yes. The BitForBytes Embedded Lab runs this exact circuit and CircuitPython code in your browser for free, with no install and no hardware. The RP2040 is emulated and runs the official firmware.
What does the code do?
analogio reads a potentiometer on GP26 and converts it to volts.
More Raspberry Pi Pico projects
- Raspberry Pi Pico LED Blink: Wiring, Code and Simulator
- Raspberry Pi Pico Push Button: Wiring, Code and Simulator
- Raspberry Pi Pico ADC + PWM LED Dimmer: Wiring, Code and Simulator
- Raspberry Pi Pico NeoPixel Ring: Wiring, Code and Simulator
- Raspberry Pi Pico DHT22 Sensor: Wiring, Code and Simulator
- Raspberry Pi Pico I2C LCD: Wiring, Code and Simulator