PyRaspBeta

Traffic light module

The traffic light module packs a red, a yellow and a green LED onto one board, each with its own 330 Ω resistor and all three cathodes shared on a single ground. It costs $6 and is for sequencing practice: a state machine that runs in the right order, a timed pattern, or a first lesson in driving more than one output. Wire red, yellow and green to three GPIOs and gnd to ground.

What's inside

PartQtyPrice each
LED3$1
Resistor3$0.25
Total6$3.75
  • Three LEDs — red, yellow and green — are the three phases.
  • Three 330 Ω resistors, one per LED, keep each colour at about 4 mA from 3.3 V; each die needs its own series resistor even though the cathodes are joined.
Exposed pinInside the kit
redr1:1
yellowr2:1
greenr3:1
gndred:K

Each signal pin is the free end of a resistor; the three cathodes are wired together internally to gnd. The kit has no chain ends, so wires go to its pins individually — pi.GPIO17 >> light will not work.

Wiring it in circuit.py

circuit.py
from wiring import *

pi = Pi()
light = kits.TrafficLight()

pi.GPIO17 >> light.red
pi.GPIO27 >> light.yellow
pi.GPIO22 >> light.green
light.gnd >> pi.GND

Driving it in main.py

main.py
from gpiozero import TrafficLights
from time import sleep

lights = TrafficLights(red=17, amber=27, green=22)

while True:
    lights.red.on()
    sleep(1)
    lights.red.off()
    lights.amber.on()
    sleep(0.5)
    lights.amber.off()
    lights.green.on()
    sleep(1)
    lights.green.off()
    lights.amber.on()
    sleep(0.5)
    lights.amber.off()

Why buy the kit

The loose parts are 3 × $1 + 3 × $0.25 = $3.75, against $6 for the module — $2.25 more for six parts pre-wired and the shared ground already joined. Hand-wiring means two wires per colour plus a ground bus; the kit is four connections. That is a fair trade for a demo board, though a single RGB LED covers the same three colours more cheaply when you only need one light.

Simulator vs real hardware

  • Each LED inside is a separate simulated part with its own forward-voltage offset, so the same overcurrent and burn-out rules apply as on the LED page.
  • The shared ground is modelled as ordinary wires between the three cathodes; the kit is one group and one shop item on the bill, not one electrical part.
  • gpiozero's TrafficLights is a convenience wrapper over three LED objects — the simulator drives it like any other output device.

Further reading