Getting Started: Reading Analog Values from a Potentiometer with Raspberry Pi Pico & MicroPython

Table of Contents
Abstract
In this article, a comprehensive step-by-step guide to interface Analog data (Potentiometer) with Raspberry Pi Pico board using MicroPython. Raspberry Pi Pico has 4 different variants (Pico, Pico 2, Pico W, Pico 2W) supporting micro-python. This articles lays the foundation for more advanced embedded system and IoT projects.
Pre-Request
- OS : Windows / Linux / Mac / Chrome
- Thonny IDE.
- MicroPython firmware in Raspberry Pi Pico / Pico 2 / Pico W / Pico 2W.
- For step by step procedure click here .
Hardware Required
- Raspberry Pi Pico / Pico 2 / Pico W / Pico 2W.
- Potentiometer (5k ohm or 10K ohm).
- BreadBoard.
- Micro USB Cable.
- Connecting wires.
- 3.3V DC power supply (optional)
| Components | Purchase Link |
|---|---|
| Raspberry Pi Pico | link |
| Raspberry Pi Pico 2 | link |
| Raspberry Pi Pico W | link |
| Raspberry Pi Pico 2W | link |
| Potentiometer | 5k Ohm : 10k ohm |
| BreadBoard | large : small |
| Connecting Wires | link |
| Micro USB Cable | link |
Don't own a hardware
No worries,
Still you can learn using simulation.
check out simulation part .
Connection Table
| Potentiometer | GPIO | Remarks |
|---|---|---|
| T1 | +3.3 V | +3.3V of Board or External 3.3V DC Supply |
| T2 | 26 (A0) | Any Analog pin (26, 27, 28) can be used |
| T3 | GND | Ground |
Note
- T1 and T2 can be interchanged in physical potentiometer.
- In Wokwi simulation, T1 is Vcc, T2 is Sig, T3 is GND.
- While using External 3.3 V supply, make sure ground pin of External Supply and Pico board is connected.

fig-Connection Diagram
Code
Code Explanation
Imports
ADCclass to configure GPIO pins (26, 27, 28) into ADC pins.timemodule for creating delay.
Initialize DHT 22 sensor.
- GPIO
26orA0is configured as Analog Input Pin.
Continuous looping & measurement.
while Trueused for continuous looping.printstatement to display the information on the terminal.time.sleep(2)2 second delay.
Read ADC value.
pot.read_u16()used to read the ADC value.- The output of
read_u16()will be of 16 bit data - Value ranging from
0to65535(i.e., 0b0000000000000000 to 0b1111111111111111) - As Raspberry Pi Pico based boards microcontroller operates at 3.3V.
- The Potentiometer terminal (T1 / Vcc) is connected to 3.3V supply
- The output of
0voltage corresponds to 0 value.3.3voltage corresponds to 65535 value.
Simulation
Not able to view the simulation
- Desktop or Laptop : Reload this page ( Ctrl+R )
- Mobile : Use Landscape Mode and reload the page
Extras
Components details
- Raspberry Pi Pico / Pico 2 : Pin Diagram
- Raspberry Pi Pico : Data Sheet
- Raspberry Pi Pico 2 : Data Sheet
- Raspberry Pi Pico W : Data Sheet
- Raspberry Pi Pico 2 W : Data Sheet
Modules / Libraries Used
- machine
machinemodule contains specific attributes and methods related to hardware on a particular board. Here classADCis imported to configure the Analog pins.- More Details
- time
timemodule provides functions related to date & time, measuring time intervals and generating delays.- More Details