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

I’ve followed the standard set by the Norwegian Public Roads Administration, in handbook 303 and 310.

  • 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

Cold start

  • 5 seconds yellow flash
  • 5 seconds yellow solid
  • 5 seconds red (minimum), all directions
  • 1 second red/yellow main direction
  • Green main direction

The build

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.

Software

The Arduino sketch can be found on GitHub:

https://github.com/thomasjsn/WeMos-Traffic-lights-controller-MQTT

Videos

  • 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.

I/O

Wemos D1 mini pinout

Outputs

  • 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

Schematic diagram

Schematics for the WeMos traffic lights controller

Parts used

  • 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

Last commit 2023-02-05, with message: Add some missing tags to posts.