This one's the hardware equivalent of printing "hello world": blink an LED with a Raspberry Pi Pico running MicroPython. It is a small build, but it gets you comfortable with digital output pins, basic wiring, and flashing MicroPython code onto the board, which you will reuse in pretty much every other Pico project.
The full tutorial, with every detail and the line-by-line code explanation, is on our site: Raspberry Pi Pico - Blink LED
What you need
- Raspberry Pi Pico W
- Raspberry Pi Pico
- Micro USB Cable
- LED Kit
- LED (red)
- LED Module
- Button and LED Kit
- 220Ω Resistor
- Breadboard
- Jumper Wires
- DIYables Sensor Kit (18 sensors/displays)
Wiring
An LED has two legs: the cathode (-) and the anode (+). Connect the cathode to GND (0V). Connect the anode to a Pico GPIO pin, GP13 in this example, through a 220Ω resistor to limit current. If you use the LED Module instead of a bare LED, you can skip the separate resistor since it's already built in, which makes wiring simpler.
How it works
With the cathode tied to GND, the LED's state depends on what you put on the anode. Drive that pin to GND and the LED stays off. Drive it to VCC (power) and the LED lights up. A Pico GPIO pin configured as digital output lets your code flip that pin between GND and VCC, which is exactly how software toggles a physical LED. You can also dim the LED by sending it a PWM signal instead of a plain on/off voltage.
Code
The code declares GP13 as a digital output using Pin(13, Pin.OUT), then toggles that pin's value to turn the LED off and on, creating the blink pattern. The full MicroPython sketch with comments explaining each step is shown below.
raspberry-pi-pico-blink-led.py
"""
This Raspberry Pi Pico MicroPython code was developed by newbiely.com
This Raspberry Pi Pico code is made available for public use without any restriction
For comprehensive instructions and wiring diagrams, please visit:
https://newbiely.com/tutorials/raspberry-pico/raspberry-pi-pico-blink-led
"""
from machine import Pin
from time import sleep
led = Pin(13, Pin.OUT)
while True:
led.value(1) # Turn the LED on
sleep(1) # Wait for 1 second
led.value(0) # Turn the LED off
sleep(1) # Wait for 1 second
Things that go wrong
Before flashing code, make sure Thonny IDE and MicroPython firmware are installed on your Pico, and that Thonny is set to the MicroPython (Raspberry Pi Pico) interpreter under Tools, Options. If the LED never lights, double check the cathode is on GND and the anode is wired through the resistor to the correct GPIO pin, since a reversed LED simply won't conduct.
Full tutorial
The complete tutorial - wiring diagram, code explanation and troubleshooting - is here: https://newbiely.com/tutorials/raspberry-pico/raspberry-pi-pico-blink-led

Top comments (0)