MicroPython blink on a Pico, LED on GP15
MicroPython on a Raspberry Pi Pico: an LED and a 220 ohm resistor on GP15 blink twice a second, and print() says on and off. The whole build, a Raspberry Pi Pico 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 10 minutes to build and run. Runs in your browser. Free, and no account needed.
The parts retail for about $4.15. On Mokxi they're free.
What you'll learn
- Controlling a pin with machine.Pin
- Turning an LED on and off with value
- Timing with time.sleep
- Why an LED needs a series resistor
- Difficulty: Beginner
- Time: About 10 minutes
- Board: Raspberry Pi Pico
- Parts: 3
How it works
GP15 goes through a 220 ohm resistor to a red LED, and the LED's other leg goes to ground. The resistor protects the LED from too much current.
The script sets the pin to 1, prints LED on and waits half a second. Then it sets 0, prints LED off and waits another half second. That is two full blinks every second.
Parts list
3 parts, plus the jumper wires. They retail for about $4.15; on Mokxi they're free.
Kits that can build it
These 4 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 pin | Connects to |
|---|---|
| Resistor, 220 Ω pin 1 | Raspberry Pi Pico pin GP15 |
| LED, red pin A | Resistor, 220 Ω pin 2 |
| LED, red pin C | Ground |
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.
# Blink an LED on GP15: GP15, a 220 ohm resistor, the LED, then ground.
from machine import Pin
import time
led = Pin(15, Pin.OUT)
while True:
led.value(1)
print("LED on")
time.sleep(0.5)
led.value(0)
print("LED off")
time.sleep(0.5)
Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- The LED stays dark This project
Check the LED direction. The anode (longer leg) goes toward the resistor and the cathode to 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. - 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.