Raspberry Pi Pico ADC + PWM LED Dimmer: Wiring, Code and Simulator

To build this Raspberry Pi Pico ADC + PWM LED Dimmer project you need a Raspberry Pi Pico and a 220 Ω resistor, a red LED and a potentiometer. ADC(26) reads a potentiometer as 0-65535; PWM on GP15 sets the LED to match. Make the 6 connections in the wiring table, upload the MicroPython code, and turn the knob: 3.3 V is the Pico full scale, and the LED dims with PWM.

Open this circuit in the free Raspberry Pi Pico simulator

Parts list

QtyPartWhat it does
1Raspberry Pi Picothe microcontroller board
1220 Ω resistorLimits current. 220 Ω in series with an LED; 10 kΩ as a pull-up or pull-down.
1red LEDLights when A (anode, the bent leg) is high and C (cathode) is low. Use a resistor.
1PotentiometerVCC to 5V, GND to GND, SIG to an analog pin. Drag the knob; analogRead gives 0–1023.

Wiring

#FromTo
1Raspberry Pi Pico GP15220 Ω resistor leg 1
2220 Ω resistor leg 2red LED anode (A, long leg)
3Raspberry Pi Pico GNDred LED cathode (C, short leg)
4Raspberry Pi Pico GP26Potentiometer SIG
5Raspberry Pi Pico 3V3Potentiometer VCC
6Raspberry Pi Pico AGNDPotentiometer GND

Step by step

  1. Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Raspberry Pi Pico. No install or account is needed.
  2. Add the parts. Add a 220 Ω resistor, a red LED and a potentiometer from the parts palette.
  3. Wire 1. Connect Raspberry Pi Pico GP15 to 220 Ω resistor leg 1.
  4. Wire 2. Connect 220 Ω resistor leg 2 to red LED anode (A, long leg).
  5. Wire 3. Connect Raspberry Pi Pico GND to red LED cathode (C, short leg).
  6. Wire 4. Connect Raspberry Pi Pico GP26 to Potentiometer SIG.
  7. Wire 5. Connect Raspberry Pi Pico 3V3 to Potentiometer VCC.
  8. Wire 6. Connect Raspberry Pi Pico AGND to Potentiometer GND.
  9. Paste the MicroPython code. Paste the MicroPython code below into the code editor.
  10. Run it. Press Run. Turn the knob: 3.3 V is the Pico full scale, and the LED dims with PWM.

MicroPython code

# Dimmer: a potentiometer on GP26 (ADC0) sets the PWM duty of the LED on GP15.
from machine import Pin, ADC, PWM
import time

pot = ADC(26)
pwm = PWM(Pin(15))
pwm.freq(1000)

while True:
    value = pot.read_u16()  # 0-65535
    pwm.duty_u16(value)
    print("pot:", value, " duty:", round(value / 655.35), "%")
    time.sleep(0.2)

What to try

Turn the knob: 3.3 V is the Pico full scale, and the LED dims with PWM.

Frequently asked questions

How do I wire the ADC + PWM LED Dimmer project on a Raspberry Pi Pico?

Make 6 connections: Raspberry Pi Pico GP15 to 220 Ω resistor leg 1; 220 Ω resistor leg 2 to red LED anode (A, long leg); Raspberry Pi Pico GND to red LED cathode (C, short leg); 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 220 Ω resistor, a red LED and a potentiometer.

Can I simulate this Raspberry Pi Pico project online for free?

Yes. The BitForBytes Embedded Lab runs this exact circuit and MicroPython 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?

ADC(26) reads a potentiometer as 0-65535; PWM on GP15 sets the LED to match.

More Raspberry Pi Pico projects