I'm still kind of new to the raspberry pi, but familiar with turning an LED on/off using the command line or a python webserver. I have a Model B Revision 2.

I've been asked to do a project that choreographs 14 strands of lights to music. I was inspired to use my RPi, after seeing a blog post by Chivalry Timbers, but I do not know how to control more than 8 channels using my RPi. I know it's possible, but need some guidance to get started.

My understanding is that I can use any 14 of the GPIO ports mapped here (http://www.raspberrypi.org/documentation/usage/gpio/images/basic-gpio-layout.png) and wire each of my 14 GPIO ports to 1 of the relays on a relay like this one (http://www.amazon.com/SainSmart-16-CH-16-Channel-Relay-Module/dp/B0057OC66U/ref=sr_1_fkmr2_1?ie=UTF8&qid=1410787622&sr=8-1-fkmr2&keywords=16+channel+relay+for+raspberry+pi). I can then connect the relays to electrical sockets like Chivalry Timbers did, in order to power the light strands on or off.

Am I on track? I'm still a NOOB when it comes to transistors, resistors, but have a basic understanding of electronics. Can anyone provide some guidance for me?

EDIT I should note that, while I understand conceptually how to do this with up to 8 relays, I've never actually done it myself (yet).

3 Answers 3


You can easily get 16 (or more) outputs using an io expander like the mcp23017. It has 25mA per output which may be enough to drive a small relay directly, otherwise it's common to use something like uln2003 to boost the signal

  • please forgive my ignorance, but could you elaborate on how I would do that (maybe include some links to illustrated examples for us visual learners?) Sep 15, 2014 at 14:35

In terms of driving the relay, I would suggest using an npn transistor to drive the channel. I have a 4 channel relay board, and this is working for me. I'm able to control 2 lights, and a 12v computer fan this way. (I haven't filled in the 4th channel yet.) as for getting more outputs, all of the pins can be set as output pins. I'm currently doing this, including the p5 header, on a RPi B (NOT B+), but this did require that I solder in the p5 header. but I am using all 21 pins as digital input / output. This is how I have my relay connected:

enter image description here

I hope this helps. :)

  • 1
    What you show here is a common collector circuit which has a significant drawback when used with the Pi's 3V3 GPIO pins - the output voltage cannot be higher than 3V3. This could be too less for 5V relays. The typical pick would be the common emitter circuit for such applications. (See here.)
    – Ghanima
    Apr 30, 2016 at 19:34

you can get a relay board with IO expander chip like MCP23008 or MCP23017 relay board . using this kind of board all you will need is I2C lines to control all the relay.

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.