5101+ reviews
Order by 16:00 for same day shipping
14 days return
GB
EN
Individual
Business
In this project you will learn how to use multiple LEDs to simulate a traffic light. Each LED is controlled via a separate GPIO pin, and you program the logic of a traffic light.
GPIO | Pin # | LED color | Function |
GPIO 17 | Pin 11 | Red | Control red LED |
GPIO 27 | Pin 13 | Yellow | Control yellow LED |
GPIO 22 | Pin 15 | Green | Control green LED |
GND | Pin 6 | All LEDs | Earth/ground connection |
from gpiozero import LED
from time import sleep
# LED's koppelen aan GPIO-pinnen
red = LED(17) # Rode LED op GPIO 17
yellow = LED(27) # Gele LED op GPIO 27
green = LED(22) # Groene LED op GPIO 22
# Verkeerslicht simulatie
while True:
# Rood licht
red.on()
yellow.off()
green.off()
sleep(3)
# Rood en geel samen (overgang)
red.on()
yellow.on()
green.off()
sleep(1)
# Groen licht
red.off()
yellow.off()
green.on()
sleep(3)
# Geel knipperend (waarschuwing)
red.off()
yellow.on()
green.off()
sleep(1)
yellow.off()
sleep(1)
If everything is connected correctly and the script is executed correctly, the traffic light will mimic the standard sequence of red, yellow, green.