traffic_lights

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
traffic_lights [2026/07/19 16:50] – created walkeradmintraffic_lights [2026/07/21 08:51] (current) – [Traffic Lights] walkeradmin
Line 1: Line 1:
 +====== Traffic Lights ======
 +<color #db5f0b>Jul 2026</color>
 +\\ 
 +\\ 
 +{{ :ws-rp2040-01.jpg?100 |}}
 +----
 +===== Introduction =====
 +\\ 
 +Works with:
 +  * Raspberry Pi Pico
 +  * RP2040 Zero Mini
 +\\ 
 +The following code works with both the Raspberry Pi Pico and the RP2040 boards from Ali. The difference is that we are using different GPIO pins. On the RPi Pico, we are using Pins 2, 6 and 10. The reason for this is that the RPi Pico has a GND pin next to each of these GPIO pins, so wiring is very simple.
 +\\ 
 +\\ 
 +----
 +==== Wiring ====
  
 +For our RP2040 mini device, we will not use these pins. There is only one GND pin so we will have to wire everything to a GND rail on our breadboard.
 +\\ 
 +\\ 
 +{{ :rp2040-traffic-light-001.png?500 |}}
 +\\ 
 +Above we can see the wiring for the RP2040 and the LEDs.
 +\\ 
 +  * Pin 6 = Red LED
 +  * Pin 7 = Amber LED
 +  * Pin 8 = Green LED
  
 +The LEDs I used are standard 5mm LEDs. 
 +\\ 
 +\\ 
 +The resistor values are 330 Ohm.
 +\\ 
 +\\ 
 +The Anode of the LEDs (the positive, normally the longer leg) goes to the GPIO pins on the RP2040. The Cathode, goes to GND via the 330 Ohm resistors.
 +\\ 
 +\\ 
 +----
 +==== The Traffic Light Micro Python Code ====
  
- +Download the code below to a new file on  your device called traffic-lights.py.
- +
- +
- +
  
 <code:python | download> <code:python | download>
Line 15: Line 49:
    
 # Define GPIO pins for the LEDs # Define GPIO pins for the LEDs
-RED = Pin(2, Pin.OUT) +RED = Pin(6, Pin.OUT) 
-AMBER = Pin(6, Pin.OUT) +AMBER = Pin(7, Pin.OUT) 
-GREEN = Pin(10, Pin.OUT)+GREEN = Pin(8, Pin.OUT)
    
 # Put them in an array # Put them in an array
Line 47: Line 81:
     time.sleep(1)     time.sleep(1)
 </code> </code>
 +\\ 
 +That's it. You should now have a working set of traffic lights :)
 +\\ 
 +\\ 
 +----
 +==== Working Example ====
 +
 +Here is a short video of a working example.
 +\\ 
 +\\ 
 +{{ :rp2040-traffic-light.mp4?480 |}}
 +\\ 
 +I hope you have some fun with this project.
 +\\ 
 +\\ 
 +----
 +
traffic_lights.1784479801.txt.gz · Last modified: by walkeradmin