I am after some technical help. I need to independently operate 29 lights. (each light must have the ability to turn on/off without depending on other light states)

Now I want to do this with a Raspberry Pi and use its GPIOs. I have no issues with the programing side, but I have no idea what components, register, boards I need in order to achieve this.

As far as I am aware the Raspberry Pi has 8 GPIOs and thus 2^8 256 components can be controlled? What do I need to achieve just 29?

I have no issues with the programming part, but please be as detailed as you can due to the fact this I am very new to the electrical side of this. Thanks

  • What do you mean by light? If each light is just a simple LED (as you've tagged) then it's quite easy (just combine 6 with 5), no special tricks necessary. If you want to control room lights on mains power then it will get trickier...
    – francis
    Feb 4, 2014 at 11:18

3 Answers 3


You are correct that you can use 8 pins in a multiplex fashion to produce more outputs, but the complexity of this, and the fact that the Linux OS is not really suitable to do this make it inappropriate.

You would be better to go with a GPIO expander. The MCP23017 is an I/O expander chip which has 16 GPIO pins which you can control using an I2C interface using two pins from a Raspberry Pi. As you actually have more than 8 outputs already (an additional 7) this would give you 16 + 8 + 7 - 2 = 29.

There are many add on boards using this chipset available at low cost.

  • I would go for two I/O expanders, so that all lights are controlled in the same way, this keeps the program simple and the system extendable when more lights are wanted.
    – Frepa
    Feb 4, 2014 at 15:02

Using GPIO means that MAX have to wire twice as many wires as the amount of slave devices you need. You might end up spending more money on copper than anything else. Also trying to find the correct wire might become really complicated.

This problem is solved with SPI daisy chaining that uses 3 copper wires to send data to all the SLAVES but only the target ID will react to your command.

enter image description here

*The image and more information can be found at this site

The downside of using SPI slaves is that each light needs some kind of microcontroller (aTiny or PIC with SPI built in or other cheap SPI - They all have to be the same thouhg). You obviously want to use the cheapest thing out there. Then you have to program every one of these to do something that you tell it to do.

That said, SPI still makes a huge saving on costs on time.


Assuming these lights are 120VAC, you could use X10 and have the GPIO ports send the data into the X10.

What is X10? X10, is a system of light switches, outlets, etc, that are assigned an ID. A transmitter sends small signals over a power line in which are picked up by these devices telling them to turn off or on.


Your Answer

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

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