Electronic – Miniature Traffic Light with Raspberry Pi: Wiring many LEDs

gpioledmultiplexerraspberry pi

Background:

I am a Civil Engineer specialized in traffic control devices and I have a small hobby project to build a scale model traffic light system. I can manage and control the traffic light pattern programming on my own using a Raspberry Pi (plus this gives me the ability to implement dynamic and programmed control, and interface with serious traffic control schema and possibly real traffic data). I just need help with wiring many LEDs on the hardware side 🙂

I followed this tutorial http://www.raspberrypi-spy.co.uk/2012/06/control-led-using-gpio-output-pin/ just fine (including using an external power source instead of Pin 2), but I am likely going to run into the problem of too few GPIO connections for all the traffic lights.

Next I tried multiplexing with an LED Matrix http://www.appelsiini.net/2011/how-does-led-matrix-work. Multiplexing works, however, the lights are usually dimmer, I doubt this will scale well, and this tends to magnify the control complexity.

Core question:

Short of getting some expansion card on the Raspberry Pi, are there any other tricks I could use to control multiple LED's with fewer 0/1 signals?

One thing about traffic lights is that they usually come in blocks of three, only one of which is ever active at a time. Is there some relatively simple circuit out there that would enable me to 'toggle' a block of LEDs using a single 0/1 signal?

Best Answer

Are you familiar with shift registers like 74HC595? It requires 3 pins from your RPI and you can control 8 output lines. You can easily cascade them effectively controlling n×8 output lines.

Data is serially clocked into the shift register and once all 8 output bits are transferred, you latch the bits onto the outputs.

I was about to add the datasheet here, but https://www.sparkfun.com/products/733 shows a nice video and has a link to the datasheet too.