Rebuilding a traffic light with an RPi
A few months ago I was given an old decommissioned traffic light by a neighbour as it was clogging up his shed. I didn’t really need a traffic light, but was interested in how it worked and, if it didn’t, could I get it working again in some sort of fashion?
As I got it, it was wired up to a standard UK plug through a cord coming through the back. When plugged in, all three bulbs lit up.
This was clearly not ideal, so obviously time to take it apart and see how it was wired up inside. This turned out to be easy as the whole unit is modular, so this one is three modules connected together. The front of each module is held on by four clips that slide out of the way, so in use this would be very easy to service.
However, after removing the fronts, what I found was a little…disappointing. I was excited to investigate what might be inside one of these, but it appears everything has been removed, and the lights were actually standard household bulb holders and household low-energy lightbulbs.
But hey, at least we know what we’re working with now, time to develop a plan. My desired outcome is to make the unit flash in the standard UK traffic light series. To do this, I decided to employ a Raspberry Pi Zero, and a relay board which plugs into the top. I originally wanted to use a Raspberry Pi Pico, but this relay board needs 5V to trigger the relays, and the Pico can only do 3.3V.
At this point, I wrote some very hacky code that I’m not willing to share, I’m not any sort of programmer, although I sometimes wish I was, I could at least earn more money. The short version is that it turns each light on and off at the right time to replicate the standard UK traffic light sequence. Luckily I could test this as I went as the relay board has an LED that corresponds to each relay, and they light up when the relay is triggered.
Now, onto putting everything together. At this point I’d stripped all the wiring and bulb holders out of the unit as I would have to rewire it accordingly, so could test it in isolation. I also took a Raspberry Pi power adaptor and stripped it out of it’s casing so I could solder on a couple of wires and attach it to the rest of the wiring.
Now that’s working, I can install it all into the traffic light housing with new wiring. I used sticky strips to secure the Raspberry Pi and power supply gubbins into the top ‘module’ and then ran wires down to each lamp from there.
And just like that, it’s a working traffic light again. I created a script to start the sequence when the RPi boots up, so all I have to do is turn it on at the wall and the sequence will begin, after a delay.
Final thoughts
I’m pleased with this, I managed to do what I set out to do and now have a fun light to entertain guests in my living room. Saying that, there is still room for improvement. Off the top of my head:
- As it’s running on a Raspberry Pi Zero, it has to boot up Debian from it’s micro-SD card before it can run the Python script to start the secret. Obviously this takes time, roughly 45 seconds from when the power is turned to when the sequence begins.
- There’s an obvious audible ‘clack’ when each relay triggers. Can be covered up with music, but it’s a bit intrusive once it’s running.
- More of a programming task, but I think it might be fun if I can trigger the relays in different orders for various ‘modes’. This could perhaps be controlled by wifi, using the Zero’s interface. This might be the ‘hard mode’ plan.
I might revisit this in the future if I can figure the answer to one or more of the above issues, but for now I’m happy.