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?

  • 1
    \$\begingroup\$ b = ceiling(ln(N)/ln(2)) where N is the number of LEDs to control, and b is the number of bits required to implement control. Thus a traffic light unit, where only 1 in 3 LED is active at a time, would require 2 I/O bits for control. With 8 bits I/O, you can control 32 traffic light units: 2 bits for data (which 1 in 3 light to turn on), 5 bits for address (which 1 in 32 or 2^5 unit you are referring to), and 1 bit for latching. I hope someone can expand this to a full answer. \$\endgroup\$
    – shimofuri
    Commented Feb 14, 2013 at 9:49
  • \$\begingroup\$ Answer below is a good one and what I was going suggest but as something simple couldn't find a good reference circuit. You could also use a small $1 8-pin microcontroller and roll your own serial bus for virtually unlimited devices although that's a bit on a project in itself if you haven't used them before. \$\endgroup\$
    – PeterJ
    Commented Feb 14, 2013 at 10:40
  • \$\begingroup\$ Searching for "[multiplexing] [led]" will find questions with both those tags. You might find some useful information there. \$\endgroup\$
    – Phil Frost
    Commented Feb 14, 2013 at 13:12
  • \$\begingroup\$ OP may enjoy this traffic light from Velleman \$\endgroup\$ Commented Feb 15, 2013 at 6:10

3 Answers 3


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.


Shift registers as jippie suggests work well. But, multiplexing can also be made to work for more LEDs than you might expect. The solution to the reduced brightness is to increase the peak current so that the average current remains the same. You can do this by increasing the voltage or reducing the current-limiting resistor.

The reason excessive current damages an LED is that the junction overheats. If given time to cool down between pulses, the pulses can be stronger. The datasheet for your LED should specify both a maximum average current, and a maximum peak current which should not be exceeded. If you aren't too concerned about high reliability (a hobby project, not a space ship) and you don't mind smoking a few LEDs or bending the rules a bit, you can always test the limits by yourself.

Also, look in to charlieplexing for a way to multiplex more LEDs from a smaller number of pins. The upper limit to how many LEDs can be connected with this method is usually the brightness achievable with the current available from the GPIO pins, not the number of pins.

Further reading: Does pulsing an LED at higher current yield greater apparent brightness?

  • 1
    \$\begingroup\$ I tend to shy away from pushing peak currents too high in the absence of circuity which can prevent a row from being left on for too long. Any software-based row drive is almost guaranteed to fail occasionally, and a well-designed circuit should be immune to damage from such occurrence. \$\endgroup\$
    – supercat
    Commented Dec 13, 2013 at 17:13

Use USB or Ethernet to control the lights via a latching relay board such as this


I've used these boards for other applications and they are excellent

  • 2
    \$\begingroup\$ We expect answers here to largely stand on their own. Links rot over time, and should not be relied on for the main information. State your answer in a paragraph or two and use links to refer to additional background information. \$\endgroup\$ Commented Feb 18, 2013 at 13:01
  • \$\begingroup\$ Fair enough! The board in question I referred to from Robot Electronics is a USB or Ethernet controlled relay driver. It comes with a simple command set to set each of the 8 or 16 relays on the board on or off. These relays can easily be used to switch the LED stack of your traffic lights and allow control via the USB or Ethernet port of the Raspberry PI \$\endgroup\$
    – Gareth
    Commented Feb 19, 2013 at 17:43
  • 1
    \$\begingroup\$ @Gareth So put this information in the answer not here. \$\endgroup\$
    – Butzke
    Commented Dec 13, 2013 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.