Two channel traffic lights controller — using Wemos
My kids wanted traffic lights for their LEGO city, so first I had to build a traffic lights controller.
I haven’t gotten around to making the actual traffic lights yet — but I have made a dual channel, Wi-Fi enabled, MQTT controlled traffic lights controller. That follows the standard set by the Norwegian Public Roads Administration.
Table of contents
Sequence and timing
- Yellow time: 3-4 seconds, depending on speed limit (above or below 50 km/h)
- Red/yellow time: 1 second
- Yellow and red/yellow time for two conflicting flows of traffic must not overlap
- Switching time:
t_switch = t_clear - t_enter
- Yellow flash: 60 times per minute (1 Hz), 50% interval
- 5 seconds yellow flash
- 5 seconds yellow solid
- 5 seconds red (minimum), all directions
- 1 second red/yellow main direction
- Green main direction
This was a really simple build, it’s all on a stripboard for now. I’m powering everything with the micro USB connector on the Wemos micro controller, but I have added pin-headers for a 5V external supply, with a protection diode.
So the only additional component needed, in addition to the Wemos, is a Darlinton-driver to power the actual LEDs. I added plenty of pin-headers to make it easy to connect the traffic light LEDs.
Lots of space 😃
For testing purposes I made two small traffic light breakout boards, I haven’t figured out how to build the actual LEGO traffic lights yet.
The Arduino sketch can be found on GitHub:
- First test with single traffic light output and MQTT communication.
- Added second traffic lights and auxiliary output.
- Faster MQTT command response.
- Added cold-start sequence on first boot or when ending yellow flash mode.
- Made two traffic light LED test boards.
- GPIO 4 : Traffic light 1, green
- GPIO 0 : Traffic light 1, yellow
- GPIO 16 : Traffic light 1, red
- GPIO 14 : Traffic light 2, green
- GPIO 12 : Traffic light 2, yellow
- GPIO 13 : Traffic light 2, red
- GPIO 15 : Auxiliary (e.g. street lights)
- GPIO 2 : Built-in LED, MQTT connection status
- 1 × Darlington-driver, 7 step, ULN2003A, DIL16, In: 2.7K/5V
- 1 × DIL socket, 16-pin, 7.62mm
- 1 × Diode, rectifier, 1 A, 400V, 1N4004
- 1 × PCB, stripboard prototyping, 94x53mm, 50cm2
- 16 × Straight pin header, female, Single row, 2.54mm
- 15 × Straight pin header, male, Dual row, 2.54mm
- 16 × Straight pin header, male, Single row, 2.54mm
- 1 × WeMos D1 mini, WiFi dev. board, ESP8266
- Making a WiFi MQTT controlled relay for Home Assistant
- Kids alarm module, Raspberry Pi Zero, and MQTT
- Stack lights for Alertmanager using Raspberry Pi
- Finding earth leakage on ATTEN 858D hot air gun
- Putting flickering LEDs in christmas decoration