Blink an LED on Raspberry Pi Pico Using MicroPython (Hardware & Simulation) : Step-by-Step Guide

Table of Contents
Abstract
Raspberry Pi Pico is a modern development board with Cortex-M0+, Dual core microcontroller supporting micro-python. Know the key features and comparison with Pico 2 version.
In this article we go through.
- Accessing the built-in led of the Raspberry Pi Pico board.
- Turning
onandoffbuilt-in led using micro python. - Simulation using wokwi.
- Hardware demo.
Pre-Request
- OS : Windows / Linux / Mac / Chrome
- Thonny IDE.
- MicroPython firmware in Raspberry Pi Pico / Pico 2.
- For step by step procedure Click here .
Hardware Required
- Raspberry Pi Pico / Pico 2.
- Micro USB Cable.
| Components | Purchase Link |
|---|---|
| Raspberry Pi Pico | Purchase Link |
| Raspberry Pi Pico 2 | link |
| Micro USB Cable | Purchase Link |
Don't own a hardware
No worries,
Still you can learn using simulation.
check out simulation part .
Connection Table
Built-in led of Raspberry Pi Pico is internally connected to GPIO 25.
| Particular | GPIO | Remarks |
|---|---|---|
| Built-in LED | 25 | Internally Connected |

Code
Code Explanation
Imports
- Importing
Pinclass from machine module to control the GPIO pins. timemodule for creating delay betweenonandoffstate.
Accessing built-in led of Raspberry Pi Pico / Pico 2 board.
- GPIO pin 25 is configured as
OUTPUTpin (Line number 5) and assigned to a variableled
Blinking LED
- Continuous loop is achieved using
while True: led.on()sets the value of GPIO 25 toHIGHor1, which in turn turns ON the LED. (line number 8)- Delay of
1second is achieved throughtime.sleep(1)method. (line number 9 & 11) led.off()sets the value of GPIO 25 toLOWor0, which in turn turns OFF the LED. (line number 10)
Try It
- Change the value in the sleep method and observe the change in the on and off time.
time.sleep(2),time.sleep(4), etc
- Use
time.sleep_ms()method to set the values in terms of milli seconds.time.sleep_ms(1000): 1000 ms or 1 stime.sleep_ms(500): 500 ms or 0.5 s
Simulation
Not able to view the simulation
- Desktop or Laptop : Reload this page ( Ctrl+R )
- Mobile : Use Landscape Mode and reload the page
Result
Above code turns ON LED for 1 second and OFF for 1 second. Similar to a square wave of 0.5 Hz output connected to an LED.
Extras
Components details
- Raspberry Pi Pico / Pico 2 : Pin Diagram
- Raspberry Pi Pico Data Sheet
Modules / Libraries Used
-
machine
machinemodule contains specific attributes and methods related to hardware on a particular board. Here classPinis imported to control the Input Output pins.- More Details
-
time
timemodule provides functions related to date & time, measuring time intervals and generating delays.- More Details