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
| Part | Qty | Price each |
|---|---|---|
| LED | 3 | $1 |
| Resistor | 3 | $0.25 |
| Total | 6 | $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 pin | Inside the kit |
|---|---|
| red | r1:1 |
| yellow | r2:1 |
| green | r3:1 |
| gnd | red: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
from wiring import *
pi = Pi()
light = kits.TrafficLight()
pi.GPIO17 >> light.red
pi.GPIO27 >> light.yellow
pi.GPIO22 >> light.green
light.gnd >> pi.GNDDriving it in 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
TrafficLightsis a convenience wrapper over threeLEDobjects — the simulator drives it like any other output device.
Further reading
- gpiozero: TrafficLights — the
red,amberandgreenattributes and sharedon()/off()helpers.