Individual assignment: Simulate a circuit#

For this assignment I used Wokwi which is basically an online simulator for microcontrollers. it supports arduino, ESP32, STM32 and the Pi Pico which is what we’ve been using in the lab

Wokwi homepage showing the available simulator options: Arduino, ESP32, STM32, and Pi Pico

I picked the Pi Pico community edition and found this traffic light example project. the cool thing about wokwi is that it uses a diagram.json file to describe the circuit, so you define each component (the pico, the leds, etc) as json objects with their type, position and attributes like color. then theres a connections array at the bottom that wires everything up by specifying which pins connect to which. so here you can see we got a red led, yellow led and green led all wired to different GPIO pins on the pico with thier grounds going to the pico’s GND pins

The diagram.json file showing the circuit definition, a Pi Pico with three LEDs (red, yellow, green) defined as JSON objects with connections array wiring them to GPIO pins

Then I looked at the sketch.ino which is the actual arduino program that runs on the simulated pico. its a classic traffic light sequence, first green goes HIGH for 3 seconds, then it switches to yellow for 500ms, then red for 2 seconds, then yellow blinks briefly before going back to green. the setup() function just sets all three pins as OUTPUT and the loop() does the cycling with digitalWrite and delay calls

The sketch.ino file showing the traffic light Arduino program with setup() and loop() functions cycling through green, yellow and red LEDs

And here is the simulation actually running. you can see the green LED is lit up on the virtual Pi Pico board and the timer in the top right shows its been running for about 12 seconds. the simulation panel lets you pause, stop or restart it which is pretty handy for debugging

The simulation running with the green LED lit up on the Pi Pico, timer showing 12 seconds elapsed

Reflections#

Wokwi is a nice way to quickly test out circuit ideas without having to physically wire anything up. the diagram.json approach is interesting because you can version control your circuit layout alongside your code. for a simple traffic light like this it works great, you can see the LEDs actually light up in the simulation which makes it easy to verify the timing logic is correct before flashing to real hardware.