Skip to content

Project 1.2.1

Potentiometer Led Brightness Controller

Overview

Build a dimmable LED using a potentiometer.

This project demonstrates analog input and PWM output.

The final result is an LED that gets brighter or dimmer as you turn the knob.

Required Components

Pico 2 W
Raspberry Pi Pico 2 W
LED
LED
Resistor
220Ω resistor
Potentiometer
10kΩ potentiometer
Breadboard
Breadboard
Jumper Wires
Jumper wires

Circuit Connections

Component Pin Connects To Pico GPIO / Physical Pin Number Notes
LED anode (+) 220Ω resistor then GPIO 0 GPIO 0 / physical pin 1 PWM output
LED cathode (-) GND Physical pin 38
Potentiometer left pin 3.3V Physical pin 36 Outer pin
Potentiometer middle pin GPIO 26 GPIO 26 / physical pin 31 ADC input
Potentiometer right pin GND Physical pin 38 Outer pin

Circuit Diagram

Step-by-Step Wiring

Step 1: Place the Raspberry Pi Pico 2W

Insert the Raspberry Pi Pico 2W onto the breadboard so that it straddles the center gap. Make sure the USB port faces outward for easy connection to the computer.

Circuit 2

Step 2: Place the LED

Insert the LED onto the breadboard.

  • Place the long leg (anode, +) in one row.

  • Place the short leg (cathode, -) in a different row.

Important: Do not place both LED legs in the same breadboard row.

Circuit 3

Step 3: Connect the Resistor

Insert one end of the 220Ω resistor into the same row as the LED’s long leg (anode).

Insert the other end of the resistor into a new empty row.

Circuit 4

Step 4: Connect the Resistor to GPIO 0

Use a jumper wire to connect the free end of the resistor to GPIO 0 on the Raspberry Pi Pico 2W.

Recommended wire color:

  • Green or yellow for signal wires.

Circuit 5

Step 5: Connect the LED to Ground

Use a jumper wire to connect the LED short leg (cathode) row to a GND pin on the Raspberry Pi Pico 2W.

Recommended wire color:

  • Black for GND connections.

Circuit 6

Step 6: Place the Potentiometer

Insert the potentiometer onto the breadboard.

Important:

  • Make sure each of the three pins sits on a separate breadboard row.

  • Do not place all three pins in the same connected row.

Circuit 7

Step 7: Connect the Potentiometer to 3.3V

Use a jumper wire to connect one outer pin of the potentiometer to the 3.3V pin on the Raspberry Pi Pico 2W.

Recommended wire color:

  • Red for power connections.

Circuit 8

Step 8: Connect the Potentiometer to GPIO 26

Use a jumper wire to connect the middle pin (wiper pin) of the potentiometer to GPIO 26 (ADC0) on the Raspberry Pi Pico 2W.

Circuit 9

Step 9: Connect the Potentiometer to Ground

Use a jumper wire to connect the remaining outer pin of the potentiometer to a GND pin on the Raspberry Pi Pico 2W.

Circuit 10

Wiring Check

Before powering the circuit, confirm:

LED long leg connects to the resistor

Resistor connects to GPIO 0

LED short leg connects to GND

Potentiometer middle pin connects to GPIO 26

One outer potentiometer pin connects to 3.3V

Other outer potentiometer pin connects to GND

No loose jumper wires

Pico is placed correctly across the breadboard center gap

Important Beginner Note

The potentiometer acts as a variable voltage divider:

  • one outer pin connects to 3.3V,

  • one outer pin connects to GND,

  • and the middle pin sends a changing analog voltage to GPIO 26 (ADC0).

Testing Individual Components

Before running the full project, test each part separately. This makes it easier to find wiring or code problems.

Potentiometer test

Check the analog reading before using PWM.

from machine import ADC, Pin
import time
pot = ADC(Pin(26))
while True:
    print(pot.read_u16())
    time.sleep(0.3)

Expected test result: The printed value changes as you turn the knob.

LED PWM test

Check that the LED can dim.

from machine import PWM, Pin
import time
led = PWM(Pin(0))
led.freq(1000)
for duty in (0, 20000, 40000, 65535, 0):
    led.duty_u16(duty)
    print(duty)
    time.sleep(1)

Expected test result: The LED brightness steps through several levels.

Full Project Code

After completing and checking the circuit connections, open Thonny IDE. Copy and paste the code below into a new file, or upload the project file to the Raspberry Pi Pico 2 W, then run it from Thonny.

from machine import PWM, ADC, Pin
import time

led = PWM(Pin(0))
led.freq(1000)
pot = ADC(Pin(26))

print('LED brightness control ready')

while True:
    adc_value = pot.read_u16()
    led.duty_u16(adc_value)
    percent = int((adc_value / 65535) * 100)
    print('Brightness:', percent, '%')
    time.sleep(0.1)

How the Code Works

Code Section What It Does Why It Matters
PWM setup Creates a PWM output on GPIO 0 PWM makes brightness control possible
ADC setup Reads the potentiometer on GPIO 26 The knob position becomes a number
duty_u16 Sets LED brightness from 0 to 65535 Matches the LED level to the knob position
Percent print Shows the current brightness estimate Helps students see what the code is doing

Expected Result

Turning the potentiometer changes the LED brightness smoothly from dim to bright.

Troubleshooting

Problem Possible Cause Solution
LED always off LED reversed or poor wiring Check LED polarity and the resistor connection
LED always full brightness Potentiometer middle pin not on GPIO 26 Reconnect the middle pin to GPIO 26
Readings do not change Potentiometer outer pins not on 3.3V and GND Rewire the outer pins correctly