Built-in project · Raspberry Pi Pico W

Pico W MicroPython blink on GP15

MicroPython on a Pico W: machine.Pin blinks an LED on GP15 through a 220 ohm resistor, a second on and a second off, and prints each change. The whole build, a Raspberry Pi Pico W and 2 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Beginner About 5 minutes to build and run. Runs in your browser. Free, and no account needed.

The parts retail for about $6.15. On Mokxi they're free.

The circuit runs here once the page has loaded.

What you'll learn

  • Driving an LED from a GPIO pin with machine.Pin
  • Why an LED needs a series resistor
  • Timing with time.sleep in MicroPython
  • Printing messages to follow what the program does
  • Difficulty: Beginner
  • Time: About 5 minutes
  • Board: Raspberry Pi Pico W
  • Parts: 3

How it works

The Pico W drives pin GP15 high, and current flows through the 220 ohm resistor and the red LED to ground. The LED lights. A second later the pin goes low and the LED turns off.

The script repeats this forever. It also prints "LED on" and "LED off" each time, so you can see the blinking in the console too.

Parts list

3 parts, plus the jumper wires. They retail for about $6.15; on Mokxi they're free.

Kits that can build it

These 2 starter kits have every part in the circuit. Each kit's page lists what else it can build.

Wiring table

Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.

Part and pinConnects to
Resistor, 220 Ω pin 2Raspberry Pi Pico W pin GP15
LED, red pin AResistor, 220 Ω pin 1
LED, red pin CGround

The code

The MicroPython code exactly as the editor opens it. Change a line there and press Run: the board runs it on the official MicroPython firmware, with nothing to compile.

main.py · Raspberry Pi Pico W
# Hello, LED: the LED on GP15 blinks, a second on and a second off.
from machine import Pin
import time

led = Pin(15, Pin.OUT)

while True:
    led.value(1)
    print("LED on")
    time.sleep(1)
    led.value(0)
    print("LED off")
    time.sleep(1)

Troubleshooting

The usual mistakes with this circuit, and the fix for each.

  • The LED never lights This project
    LEDs only work one way. The anode (A) side goes to the resistor and the cathode (C) side goes to ground. Try flipping it.
  • The messages print but the LED stays dark This project
    Check that the resistor connects GP15 to the LED, and that the LED's other leg reaches ground.
  • The LED is dim, burns out, or the pin reads wrong because the resistor value is off. Resistor
    Read the color bands again. A 220 ohm to 330 ohm resistor suits a typical LED on 5 V. 10k is a common pull-up or pull-down value. Check with a multimeter if unsure.
  • A pull-up or pull-down resistor is missing, so the input floats and reads random values. Resistor
    Tie the input to 5 V or ground through about 10k. Or use INPUT_PULLUP and wire the switch to ground.
  • The LED does not light, or it lights once and then dies. LED
    LEDs have polarity. The longer leg (anode) goes toward the positive side. Always add a series resistor, about 220 ohms to 1 k ohm on a 5 V pin.
  • A blue or white LED stays dark on 3.3 V. LED
    Blue and white LEDs drop about 3 V, so 3.3 V leaves almost nothing for the resistor. Use a 5 V supply, or a smaller resistor and a red or green LED.
  • Pins are powered from 5 V, or a 5 V signal goes into a GPIO. The RP2040 pins are 3.3 V only and are not 5 V tolerant. Raspberry Pi Pico W
    Power the board from VBUS or VSYS at 5 V, but keep GPIO signals at 3.3 V. Use a level shifter or a divider for 5 V parts.
  • WiFi code fails to connect, or the on-board LED code does nothing. The LED on the Pico W is not on GP25 like on the plain Pico. Raspberry Pi Pico W
    Use the board's LED_BUILTIN name so the library drives it through the WiFi chip. Join a 2.4 GHz network only, with the right SSID and password, and wait for the link before sending.

Change it and keep it

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