Built-in project · Raspberry Pi Pico

MicroPython blink on the Pico’s own LED, GP25

MicroPython on a Raspberry Pi Pico: machine.Pin toggles the board’s own LED on GP25 every half second and prints each change. The whole build, a Raspberry Pi Pico, 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 $4. On Mokxi they're free.

The circuit runs here once the page has loaded.

What you'll learn

  • Using the board's built-in LED
  • Flipping a pin with toggle
  • Reading a pin back with value
  • Running code forever with while True
  • Difficulty: Beginner
  • Time: About 5 minutes
  • Board: Raspberry Pi Pico
  • Parts: 1

How it works

The Pico has its own LED, wired inside the board to GP25. So there is nothing to build. No parts and no wires.

The script makes GP25 an output. Every half second it flips the pin with led.toggle() and prints whether the LED is now on or off.

Parts list

1 part, plus the jumper wires. They retail for about $4; on Mokxi they're free.

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
# Blink the Pico's own LED, which is wired to GP25, every half second.
from machine import Pin
import time

led = Pin(25, Pin.OUT)

while True:
    led.toggle()
    print("LED", "on" if led.value() else "off")
    time.sleep(0.5)

Troubleshooting

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

  • You look for the LED on the breadboard This project
    This LED is on the Pico board itself. Watch the Pico, not a breadboard part.
  • The Pico does not show up as a drive, or the program will not load. Raspberry Pi Pico
    Hold the BOOTSEL button while you plug in USB. A drive named RPI-RP2 appears. Then copy the UF2 file onto it.
  • A 5 V signal or sensor is wired to a GPIO pin. Raspberry Pi Pico
    Pico GPIO pins are 3.3 V only and are not 5 V tolerant. Use a level shifter or a voltage divider for any 5 V output going into the board.

Change it and keep it

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