How to Simulate LED Blinking with Raspberry Pi Pico on Wokwi
Learn how to blink an LED using a Raspberry Pi Pico — entirely in your browser.
This tutorial walks through Wokwi setup, wiring, MicroPython code,
and the complete diagram.json — no hardware required.
What is Wokwi?
Wokwi is a free, browser-based electronics simulator that lets you build and test embedded systems projects without any physical components. It's ideal for students, hobbyists, and educators.
Learning Electronics
Safe environment to experimentTesting Circuits
Validate designs instantlyDebugging Code
Serial monitor & live feedbackIoT Prototyping
WiFi, sensors, and moreStep-by-Step: LED Blinking on Wokwi
-
1
Open Wokwi and Create a New Project
Open your browser and go to wokwi.com. Click "New Project" and select Raspberry Pi Pico as your board. Wokwi will generate a blank project with the Pico already placed on the canvas.
No account needed to run simulations — but signing up (free) lets you save and share your projects.
-
2
Add Components
Click the blue "+" button in the top-right of the canvas to open the component picker. Add the following:
- LED — choose Red or any color you like
- Resistor — set value to
220Ωor330Ω
-
3
Position Components
Drag the LED to the left of the Pico. Place the resistor between the Pico's GP5 pin and the LED's anode (+). Neat placement makes wiring easier — think of it as a real breadboard layout.
-
4
Wire the Circuit
Click on a pin to start a wire, then click another to connect. Follow this wiring table:
From To Wire Color GP5 (Pin 7) Resistor leg 1 Green Resistor leg 2 LED Anode (+) Green LED Cathode (–) GND (Pin 3) Black Always use a resistor in series with an LED. Without it, excess current will burn out the LED (and potentially the GPIO pin).
-
5
Write the MicroPython Code
Click on the code editor tab (left panel) and paste the following MicroPython program:
MicroPython — main.pyfrom machine import Pin from utime import sleep sleep(0.01) # Wait for USB to initialise print("Hello, Pi Pico!") led = Pin(5, Pin.OUT) # GP5 = physical pin 7 while True: led.toggle() # Flip LED state sleep(0.5) # 500ms on / 500ms off
How it works:
Pin(5, Pin.OUT)sets GP5 as an output.led.toggle()flips its state every 0.5 seconds, creating the blink effect. -
6
Run the Simulation
Click the green ▶ Play button at the top of Wokwi. You should see the red LED blinking on and off every half second. The serial monitor will also print "Hello, Pi Pico!" on startup.
diagram.json — Complete Circuit Definition
Wokwi stores circuits as a diagram.json file.
Copy the code below and paste it into the diagram.json tab in your Wokwi project to instantly recreate this circuit.
{
"version": 1,
"author": "MakeMindz",
"editor": "wokwi",
"parts": [
{
"type": "wokwi-pi-pico",
"id": "pico",
"top": 0,
"left": 0,
"rotate": 0,
"hide": false,
"attrs": {}
},
{
"type": "wokwi-led",
"id": "led1",
"top": -2.67,
"left": -65.33,
"rotate": 0,
"hide": false,
"attrs": { "color": "red" }
}
],
"connections": [
[ "pico:GP5", "led1:A", "green", [ "h0" ] ],
[ "pico:GND.2", "led1:C", "black", [ "h0" ] ]
]
}
Note: This simplified diagram connects GP5 directly to the LED anode without an explicit resistor part, as Wokwi's LED model includes internal current limiting. For real-world hardware, always add a 220Ω–330Ω resistor.
All 20 Raspberry Pi Pico Projects
This tutorial is part of a complete series. Work through them in order to build your skills progressively.
Comments
Post a Comment