This tutorial shows how to create a traffic light simulator using Raspberry Pi Pico in the Wokwi online simulator. Wokwi is a free, browser-based electronics simulator - perfect for testing projects without physical hardware.
Getting Started with Wokwi
Step 1: Access Wokwi Simulator
- Go to https://wokwi.com
- Click on "Start from Scratch" or "New Project"
- Select "Raspberry Pi Pico" as your board
- Go to https://wokwi.com
- Click on "Start from Scratch" or "New Project"
- Select "Raspberry Pi Pico" as your board
Step 2: Add Components to Your Circuit
Adding the Raspberry Pi Pico:
- The Pico should already be on the canvas
- If not, click the "+" button and search for "Raspberry Pi Pico"
Adding LEDs:
- Click the blue "+" button in the parts panel
- Search for "LED" and click to add
- Add three LEDs total (you can change colors after placing them)
- Click each LED to select it, then use the properties panel to set colors:
- First LED: Red
- Second LED: Yellow
- Third LED: Green
Adding Resistors:
- Click the "+" button
- Search for "Resistor"
- Add three 220Ω or 330Ω resistors (one for each LED)
Adding the Raspberry Pi Pico:
- The Pico should already be on the canvas
- If not, click the "+" button and search for "Raspberry Pi Pico"
Adding LEDs:
- Click the blue "+" button in the parts panel
- Search for "LED" and click to add
- Add three LEDs total (you can change colors after placing them)
- Click each LED to select it, then use the properties panel to set colors:
- First LED: Red
- Second LED: Yellow
- Third LED: Green
Adding Resistors:
- Click the "+" button
- Search for "Resistor"
- Add three 220Ω or 330Ω resistors (one for each LED)
Step 3: Wire Your Circuit in Wokwi
Diagram .json:
{
"version": 1,
"author": "Uri Shaked",
"editor": "wokwi",
"parts": [
{
"type": "wokwi-pi-pico",
"id": "pico",
"top": 20,
"left": 60,
"attrs": { "env": "arduino-community" }
},
{
"type": "wokwi-led",
"id": "led1",
"top": 3,
"left": 0,
"attrs": { "color": "red" }
},
{
"type": "wokwi-led",
"id": "led2",
"top": 48,
"left": 0,
"attrs": { "color": "yellow" }
},
{
"type": "wokwi-led",
"id": "led3",
"top": 98,
"left": 0,
"attrs": { "color": "green" }
}
],
"connections": [
[ "pico:GND.1", "led1:C", "black", [] ],
[ "pico:GP1", "led1:A", "blue", [] ],
[ "pico:GND.2", "led2:C", "black", [] ],
[ "pico:GP5", "led2:A", "blue", [] ],
[ "pico:GND.3", "led3:C", "black", [] ],
[ "pico:GP9", "led3:A", "blue", [] ],
[ "$serialMonitor:RX", "pico:GP0", "", [] ]
]
}
Connecting the Red LED:
- Click on the red LED's anode (positive/longer leg shown in simulator)
- Drag a wire to GPIO 15 on the Pico
- Connect the LED's cathode to one end of a resistor
- Connect the resistor's other end to any GND pin on the Pico
Connecting the Yellow LED:
- Connect yellow LED anode to GPIO 14
- Connect cathode through a resistor to GND
Connecting the Green LED:
- Connect green LED anode to GPIO 13
- Connect cathode through a resistor to GND
CODE:#define RED 1#define YELLOW 5#define GREEN 9
void setup() { pinMode(RED, OUTPUT); pinMode(YELLOW, OUTPUT); pinMode(GREEN, OUTPUT);}
void loop() { digitalWrite(GREEN, HIGH); delay(3000);
digitalWrite(GREEN, LOW); digitalWrite(YELLOW, HIGH); delay(500);
digitalWrite(YELLOW, LOW); digitalWrite(RED, HIGH); delay(2000);
digitalWrite(YELLOW, HIGH); delay(500); digitalWrite(YELLOW, LOW); digitalWrite(RED, LOW);}
Wokwi Tip: In Wokwi, you can click and drag to create wires. The simulator automatically routes them neatly.
Connecting the Red LED:
- Click on the red LED's anode (positive/longer leg shown in simulator)
- Drag a wire to GPIO 15 on the Pico
- Connect the LED's cathode to one end of a resistor
- Connect the resistor's other end to any GND pin on the Pico
Connecting the Yellow LED:
- Connect yellow LED anode to GPIO 14
- Connect cathode through a resistor to GND
Connecting the Green LED:
- Connect green LED anode to GPIO 13
- Connect cathode through a resistor to GND
CODE:
#define RED 1
#define YELLOW 5
#define GREEN 9
void setup() {
pinMode(RED, OUTPUT);
pinMode(YELLOW, OUTPUT);
pinMode(GREEN, OUTPUT);
}
void loop() {
digitalWrite(GREEN, HIGH);
delay(3000);
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, HIGH);
delay(500);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, HIGH);
delay(2000);
digitalWrite(YELLOW, HIGH);
delay(500);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, LOW);
}
Wokwi Tip: In Wokwi, you can click and drag to create wires. The simulator automatically routes them neatly.
Comments
Post a Comment