Raspberry Pi Lights: how to sync Christmas lights to midi audio

** UPDATE 9/21/2014 **

I updated the source code today. Now lightorgan supports more than 7 output channels.  It chooses the pin to light up based on both the pitch and the octave of every note. Now the number of supported output channels is limited only by how dynamic the range of the midi file is. I observed that this worked practically for at least 24 channels on several Christmas songs. This is cool because the new Rasperry Pi Model B now supports up to 28 pins!  See Gordon’s page at http://www.wiringpi.com.

Also, the WiringPi pins that lightorgan uses are now configurable. Just modify the array called pinMapping[] that’s near the top of the lightorgan.c file to add, remove, or remap a lightorgan channel to a corresponding WiringPi  pin. Recompile with your changes and then you should be good to go.

Check out the new source code from the google code page:

svn checkout http://pi-lightorgan.googlecode.com/svn/trunk/ pi-lightorgan-read-only


Special thanks to KnC for collaborating with me on getting this up and running!



Check out Todd Gile’s project which uses the Raspberry Pi to sync mp3 audio by way of real time sampling! It’s really an awesome project, and if you want to use mp3 instead of midi, you should definitely check it out. https://bitbucket.org/togiles/lightshowpi


I’m recommending the use of the SAINSMART mechanical relays instead of the solid state ones I was originally using. There have been some reports that the PI does not have enough amperage to drive the solid state relays in some cases.

This post will show you the details of my Raspberry Pi powered synchronized Christmas lights project.  I really enjoyed working on this and I wanted to share it with anyone interested in this sort of thing.

It’s fun to begin at the end, so here is a video of the Pi Lights playing to Star Wars.

Also, the Peanuts theme song:

Theory of operation:

Untitled drawing

First, a Midi file is fed into Linux’s ALSA midi sequencer service, destined to be played on a particular port.  The sequencer then broadcasts accurately timed midi events to all programs subscribed to said port.  One of those programs is Timidity, which is a free midi synthesizer that will take care of playing the sound.  The other is a simple C program that I wrote to  control the GPIO pins based on midi events.  Each GPIO pin controls a solid state relay, which ultimately toggles the main electricity  going to each bank of  lights.

Materials required:

1 Raspberry Pi and case


SainSmart 8-Channel 5V Solid State Relay Module Board  (30$ on amazon.com)

Female to male jumpers

Cooper Wiring Devices 15-Amp White Duplex Electrical Outlet

6 Electrical outlets ( < $1 US  each)

CARLON 2-Gang Plastic Old Work Electrical Box 2-Gang Almond Standard Duplex Receptacle Plastic Wall Plate 2-Gang Light Almond Blank Nylon Wall Plate

3 Electrical boxes and cover plates  (prices vary)

 50' 14 AWG Non-Metallic Wire

50 feet of Electrical cable of appropriate gauge

IDEAL 50-Count 1/2-in Plastic Insulated Staples

A bag of electrical cable staples

Plytanium 15/32 x 4 x 8 Pine Sheathing Plywood

Enough Plywood to build a ~24″/12″/24″ box

Product Details

A small amplifier (~$20 amazon):

PYLE PLMR24 3.5-Inch 200 Watt 3-Way Weather Proof Mini Box Speaker System (White)

Outdoor speakers: (~$20 amazon )

Software needed:

Debian Rapsberry Pi distro  (http://www.raspberrypi.org/downloads)

Timidity (apt-get install timidity)

Alsa devel libraries (http://www.alsa-project.org/main/index.php/Main_Page)

Gordon’s wiringPi library (https://projects.drogon.net/raspberry-pi/wiringpi/)

About Midi Files:

Midi files are comprised of a sequence of events that richly describe how to play a song.  There are many different kinds of events, but the most interesting ones for my purposes are the NOTE ON and NOTE OFF events.

NOTE ON event {

Note value: { 0..127 }

Channel { 0..15 }


NOTE OFF event {

Channel { 0..15 }


Think of the note value part of the NOTE ON event as corresponding to key on an imaginary piano that has 128 keys.

Controlling the GPIO pins based on midi events:

I decided to control the pins based on the pitch of the notes.  There are 12 notes in an octave, so the pitch is obtained by taking modulus 12 on the note value.  From there, it’s again divided among the number of pins.  Using 6 pins, pin 0 corresponds to notes with pitch 0-2, pin 1 corresponds to 2-4, etc.

Getting Started – Software:

The first thing to do is download Timidity and make sure midi playback works properly.  After installing, configure it to run as a daemon.  Then use the ‘aconnect -o’ command to verify that it is listening on a midi port.  It should display something like this:

client 14: ‘Midi Through’ [type=kernel]
0 ‘Midi Through Port-0’

client 128: ‘TiMidity’ [type=user]
0 ‘TiMidity port 0 ‘

Try playing a midi file using the ‘aplaymidi’ command.  For example, ‘aplaymidi –port 128 yourMidiFile.mid’.

It’s probably the case that the default Timidity settings will be too aggressive for the Raspberry Pi to handle.  The midi playback may stutter and crackle.  To remedy this, modify the /etc/timidity/timidity.cfg file.  Uncomment these lines and restart Timidity.

opt EFresamp=d          #disable resampling
opt EFvlpf=d            #disable VLPF
opt EFreverb=d          #disable reverb
opt EFchorus=d          #disable chorus
opt EFdelay=d           #disable delay
opt anti-alias=d        #disable sample anti-aliasing
opt EWPVSETOZ           #disable all Midi Controls
opt p32a                #default to 32 voices with auto reduction
opt s32kHz              #default sample frequency to 32kHz

Once that’s all sorted out, it’s time to get started with the pin controller program.  You’ll need to download Gordon’s wiringPi library.  Download the latest software from the his repository, and follow the easy installation instructions (https://projects.drogon.net/raspberry-pi/wiringpi/).

The ALSA libraries should be installed by default on debian.  If you are using a different distro, go to http://www.alsa-project.org/main/index.php/Main_Page and get the latest development libraries.

You can then download the source code for my program here, called light organ.  http://code.google.com/p/pi-lightorgan/source/browse/trunk/lightorgan.c.  Check out the code to your pi using this command:

svn checkout http://pi-lightorgan.googlecode.com/svn/trunk/ pi-lightorgan-read-only

Compile the program by issuing the ‘make’ command.  Feel free to edit the code to suit whatever new ideas you come up with.

At this point, you should have a binary for the pin controlling program.  Run lightorgan as root.  Open another terminal and issue the command ‘aconnect -ol’ to list all of the active midi outputs.  You should see three entries: Timidity, lightorgan and the midi thru port.  The midi thru port needs to be configured to send it’s output both to lightorgan and Timidity.  Here is an exmaple of doing that:

aconnect -ol

client 14: ‘Midi Through’ [type=kernel]
0 ‘Midi Through Port-0’
client 128: ‘TiMidity’ [type=user]
0 ‘TiMidity port 0 ‘
client 129: ‘LightOrgan’ [type=user]
0 ‘listen:in       ‘

aconnect  14:0 128:0

aconnect 14:0 129:0

aconnect -ol

client 14: ‘Midi Through’ [type=kernel]
0 ‘Midi Through Port-0’
Connecting To: 128:0, 129:0
client 128: ‘TiMidity’ [type=user]
0 ‘TiMidity port 0 ‘
Connected From: 14:0
client 129: ‘LightOrgan’ [type=user]
0 ‘listen:in       ‘
Connected From: 14:0

At last, the ports are configured properly.  Now all midi traffic destined for port 14 (the through port) will be copied to ports 129 and 128 – Timidity and lightorgan.  You can use aplaymidi –port 14 midifile.mid to send to both Timidity and lightorgan.

If you’ve reached this point and everything is setup properly – you should be able to test the setup using a breadboard and some LEDs.  Here is an example with 4 LEDs:

In the file lightorgan.c, change MY_NUM_PINS to be the number of pins you plan on using.

Wire your pins to the LEDs using the chart at Gordon’s site: https://projects.drogon.net/raspberry-pi/wiringpi/pins/

Be sure to check out his tutorial on how to get started with GPIO on the Pi for more information.

Putting it all together:

I chose to build an enclosure using plywood to house the PI, the amplifier, outlets, relays, and connectors:

Photo: Construction has begun for my sound synchronized christmas light project. The photo shows six solid state relays and a half completed wooden enclosure. Also, a cat named dewey.

The junction box on the left is where the power comes in.  From there, individual runs of romex are run across to each relay, the ‘hot’ wire for each of these runs is separated by a solid state relay.  When voltage is run through the bottom terminals of a relay, the power is able to travel freely onto the outlet on the right side:

Photo: Oh what tangled webs we weave.

Shown above are 8 outlets (and also, my cat Dewey).  Two of the outlets are not connected to the relays, they are there to provide power for the Pi and the amp.  The connections on the left side are yet to be made.  Here is a view from another angle:


From here, the only thing left to do is complete the enclosure, add in the amp, add the Pi and wiring from the Pi.


This is the finished state of the box.  I probably should have cleaned it up a bit more, but I was too eager to see it in action. With everything being in an outdoor environment, I put a container of Damp-Rid in the box to try to mitigate the threat of condensation.

I hope this has been helpful.  If you have any questions, please comment.

-Chivalry Timbers

This entry was posted in Uncategorized. Bookmark the permalink.

308 Responses to Raspberry Pi Lights: how to sync Christmas lights to midi audio

  1. Pingback: Pumpkin Pi | The Accidental Adept

  2. Hello there! I just recently came across your great post as I’m looking for a unique solution. Have you given any thought on a version of this system that could transmit wireless data to other control boxes such as the one you’ve made? Essentially, could I have a distribution box that plays my files and controls the lights on my house but my neighbor’s house as well?

    Thanks for the great info already!

    • Chivalry Timbers says:

      Hi Sean, thanks for the feedback!

      I think your goal of having multiple control points is very acheivable using multiple Raspberry Pis and a wireless network. Here’s what I suggest you try:

      1) Get LightOrgan running as a service on both Pi’s using the instructions in this post.
      2) On the ‘client’ or ‘listener’ pi, Use the ‘aseqnet’ command to create an ALSA sequencer connector over the network. See this page for a reference (http://ccrma.stanford.edu/planetccrma/man/man1/aseqnet.1.html) – or just use the man page. Use ‘aconnect’ to connect the network sequencer port to route to port 14 (AKA the MIDI THRU port that LightOrgan listens on)
      4) On the ‘server’ or ‘broadcaster’, use ‘aseqnet’ and ‘aplaymidi’ to play a midi file onto the network port. Use ‘aconnect’ route data from local port 14 to the aseqnet port.

      In summary, here’s a diagram

      [From Server PI, ]
      [play midi file to 14]
      ...|---> Rendered on Server, LightOrgan
      ...|---->Rendered on Server, Timidity
      ...|---> Network Connected Sequencer Port
      ............->Rendered on client (remote) LightOrgan

      • Anonymous says:

        How do I load the songs I want? I have them in midi format but I cant seem to load them? When I start My pi it auto runs some music, where is that pulling from?

  3. Thank you very much!! I’m using your code to realize simple Musical Christmas Light for my children.

    It is a great work!

  4. steven says:

    can you play the music via pin 4 fm radio instead of using speakers

    • Chivalry Timbers says:

      I imagine that it’s possible. The first step would be to change the light organ source code to never use pin number 4. I’m not really sure what to do after that though. Good luck

  5. I just built a setup using this as a guide and bought the same solid state resisters that you have listed above. I’m having a problem. No matter how I wire up the breadboard, I can’t get enough juice to flip the relay completly. I played around and I got it to barely flip, but not enough to bring the lights on completely.

    I have tried it with a 9v battery so I know the relays work.

    I have also tried with LED lights on the breadboard and that works like a charm.

    Any advice? or could you give a more detailed example of how you went from the pi pins to the relays?

    • Anonymous says:

      Followup Question – I’ve been doing some research and I think if I put a transistor utilizing the 5v power supply off the pi (breadboard setup for this), it would give it enough juice to flip the SSR.

      Anyone have any experience?

      • wynneth says:

        The problem with trying to power the relays off the pi directly is a matter of current. Without any USB devices, the 5v of the pi can only provide 200 to 300mA. Depending on which particular relays you use, each relay might use 15-80mA of current. It wouldn’t take many to draw too much. Keep in mind, if you attach anything USB to the pi then that requires current too. I have the sainsmart 8 channel ssr board and I just connected a
        Separate 5v power supply to the relay board. The pi gpio pins only have to provide a tiny signal to turn the relays on and off, but not actually power them.

      • Chivalry Timbers says:

        If you’re using the same resistors that seems a bit odd that they wouldn’t flip. I would try to run the PI without anything USB plugged in as a test. Also, check to make sure that you’re using a 1000mA power supply for the pi. The transistor and external power supply method would definitely work and you can utilize your breadboard, some transistors, and an external power source.

      • Thanks for the information. I’ll give it a try when I get back into town later this week.

      • I got a chance to try it last night. The GPIO pin by itself would not every cause the SSR to flip. I hooked up a transistor using the 5 V power on the PI and it all works find now. It is a 1000 mA Power Supply. Very strange that we are getting different results. I did some looking around on the web and it appears the lower end results on SSR depend significantly on batches and manufacturing locations.

      • Chivalry Timbers says:

        That is odd indeed Tim, I’m going to update the page to recommend Wynneth’s sainsmart relays so others don’t run into the same issue. Thanks for your feedback and goodluck.

      • Tarcas says:

        I also use a separate power supply for my relays. Doing my bench tests, I discovered that the Pi 2 could power 8, but when I added 4 more for a total of 12, the Pi would freeze up while playing songs. I assume that the CPU processing the MIDI file put the power demand just high enough that it couldn’t handle it. Now I’m running the Pi and speakers off of one power supply and the relays off of a 2nd one. This way if the relays draw too much, at least the Pi can keep going and the problem should work itself out as relays get switched back off.

  6. So, could I provide the 5v power or more to the breadboard from another source and use a transitor with the GPIO pin as a signal to it?

    I’ve already built the setup with SSR and have it all enclosed safely at this point, so If I can make it work simply then I’m inclinded to try.

    • I’ve had the same problem. I ordered the same sort of relays, and I’ve found that 5 of the 8 work fine with the GPIO pins, but 3 will not switch. They do fine with a 9 volt though. I’ve resorted to ordering the sainsmart board the others are using.

      I did find that using a 2000 mA power supply and putting my wifi dongle off to a powered USB hub, the GPIO voltage increases just enough to get 1 of the 3 relays to switch. So I’m down to two that don’t work.

      My idea for getting the other two to work was to wire up a quick little darlington transistor switch and plug a 9-volt into it and just have it draw current from that to actually switch the SSRs. I decided though that doing that for two channels was too complicated, and would rather get a single board with reliable specs….

  7. Kyle says:

    I was wondering if there is any other way to get the alsa libraries besides the one in your post.

  8. Dennis Kelley says:

    I am using a 8 channel Relay board. 6 of the 8 relays only fire for any of the midi files I have. I know you mentioned ‘In the file lightorgan.c, change MY_NUM_PINS to be the number of pins you plan on using.’ in changed the file and it still does not fire the last two relays. is there something else I need to do to get all the relays to work?

    • Chivalry Timbers says:

      Hi Dennis, the problem with having more than 6 pins is that most songs are played in certain “key”. That key usually uses a maximum of 7 different pitches. LightOrgan uses the pitch of the note to decide which pin to fire. It doesn’t know what the key is of the song is while it’s being played. If it did, it could effectively use 7 pins. Unfortunately, it’s not that smart, so it uses a maximum of 6 pins as a result. That seventh pin is lost due to rounding errors from not knowing what the key of the song is.

      I have a solution for you though. I updated the lightorgan code (at googlecode page) and added options for dedicating pins to play the PERCUSSION, SYNTH, and BASE instruments. These instruments aren’t played by the 6 melody pins, but you can certainly use them to make an impressive light show and make use of your seventh and eighth channels.

      In your case, where you have 8 total pins, this is how I suggest you set it up:

      1. Get the latest lightorgan.c from googlecode
      2. Modify lightorgan.c to read
      #define NUM_MELODY_PINS 6
      int PERCUSSION_PIN_IDX = 7;
      int BASE_PIN_IDX = 6;
      int SYNTH_PIN_IDX = 6;

      This will give you 6 “Melody” pins (pins 0-5) that will be dynamic with respect to the pitch of the midi. The PERCUSSION track (drums) will play on pin 7. Any BASE or SYNTH instruments will play on pin 6.

      Hope this helps,

      Chivalry Timbers

      • Dennis Kelley says:

        I can see how this should work. But i am not sure how to use the extra pins. you said ‘These instruments aren’t played by the 6 melody pins, but you can certainly use them to make an impressive light show and make use of your seventh and eighth channels.’ but how do i use them? so am i just not using a midi file that has percussion? should i try another file. Thank you by the way for the change is code and for a great tutorial.

      • Chivalry Timbers says:

        Dennis, all you have to do is download the new code, make the changes I suggested, then recompile it.

        Yes, the songs that you use do matter in that they must use a percussion / base / synth for you to see an effect. But chances are high that the songs you are using already do have some of those instruments. Try it out with a few songs and get back to me.

      • I tried the new code and it works great for the bass and drums. However, it is not picking up any percussion instruments.

        Looking at my midi files, I don’t see anything that stands out to me as Percussion. I see plenty of drums and bass.

        Are percussion tracks rare?

        Should I change it to the following and give up on percussion?:
        int PERCUSSION_PIN_IDX = 7;
        int BASE_PIN_IDX = 7;
        int SYNTH_PIN_IDX = 6;

      • By the way, I’m assuming Base is Bass, please let me know if I”m wrong on that.

      • Chivalry Timbers says:

        Yep, it’s bass 🙂 you can certainly put percussion on the same channel as bass or synth. Percussion is aka the drum track, it seems to not be used very often

  9. Dennis Kelley says:

    That is what I was doing wrong. which was one of my questions. Did i have to recompile it.
    I am new to programming and the Raspberry pi. So that info helps me.

    Thank You!

    • Tarcas says:

      Yes, any time you change the code of any compiled language, you need to recompile it for the changes to take effect. This takes your code and makes a new program from it. You could, without any problem at all, use the same code with minor changes (variables, number of pins, etc) to make several programs any or all of which can be run. Just use different names for the compiled program.
      Interpreted languages are different (Python, Bash, Javascript, etc) because you’re not actually making a standalone program, you’re invoking another program to interpret your file which is nothing more than a list of instructions written in a language that the program knows how to interpret and act upon.
      Hope that helps!

  10. I ran into a new issue yesterday and today. Overnight, the sound stops working. I check aconnect -ol and it shows all the ports mapped correctly, however no sounds play. The lights flash.

    I tried playing directly with Timidity and sound works.

    If I reboot, everything works fine.

    This is rather annoying because I was wanting to just leave the thing running non-stop but now I have to reboot every day for it to work.

    I’ve tried search for errors on the programs, but can’t find anything.

    Any ideas?

    • Chivalry Timbers says:

      Tim, I too have this issue, it’s really annoying!

      The problem is that timidity just seems to stop working after about 24 hours or so. After I issue “service timidity restart”, the problem seems to be resolved. I haven’t looked into it too much, anyone else experience this?

      • I’ll try that tomorrow. If it works, I’ll just add it to my initialization script to run before 1st song.

        Do you have to remap it with aconnect after restarting it?

      • Chivalry Timbers says:

        Yes, you do have to remap unfortunately

      • alseadon says:

        if you have it set to start running on boot like I do you can just hook it up to a timer and let the timer reboot for you

      • wynneth says:

        If it’s an issue of the daemon/service not working correctly a full reboot isn’t always necessary. You can setup a cron job to stop and restart the service in question at set intervals. I’ve currently got my light show running completely automated with the use of cron. Mine’s a bit different than the default setup here and the images provided: I use lightorgan, but I just use aplaymidi to route the midi output to lightorgan (no timidity) and play a matching full audio mp3 file with omxplayer out to my fm transmitter. I setup shell scripts for each song (to match the timing of starting the midi and the mp3 audio), and a shell script to loop the playlist until the date command shows it to be 11pm. In cron I have the looping script begin at 6pm, another cron job starts a second “metal music” only show for a bit after 11pm, then another job turns just the icicle lights on for the rest of the night and then off in the morning. Here’s Slayer’s South of Heaven: http://www.youtube.com/watch?v=L4mEm0hVnAU

      • I’ve got it set where Cron runs my script at set intervals. If it is in the window I have set to start, it starts, else it just exits.

        I’ll add to the execute part if it passes to restart timidity and aconnect commands before starting to play the songs.

      • Here is the script I wrote for crontab to run. It also has the option if you put a time at the end it will consider it the stoptime (1420 means 2:30 PM).

        It works well but I’m always open to suggestions.

        # Grab initial time
        TIME=$(date ‘+%k%M’)

        # Setup Initial Variables
        FILES=/SHARES/MIDI #Need to put in the right path

        # Test for time input
        if [ “x$1” != “x” ]

        # Reset the services
        service timidity restart
        # Pause to give time to line out
        sleep 5
        # remap to midi player port
        aconnect 14:0 128:0

        # Loop until time exceeds endtime
        while [ $TIME -lt $ENDTIME ];do

        # Runs ls on the given dir, and dumps the output into a matrix,
        # it uses the new lines character as a field delimiter, as explained above.
        file_matrix=($(ls “${FILES}”))

        # Play the File
        aplaymidi –port 14:0 $FILE

        # Need to recalc time
        time=$(date ‘+%k%M’)


  11. Wynneth, how did you get a MP3 and Midi file to be the same length and such? As I read around everyone says there is not a decent converter for an MP3 file to Midi.

    Also, does anyone have a favorite program on adjusting midi file volume? I’ve found mine change in volume so much, it either can’t be heard or the neighbors are calling.

  12. NR says:

    Does anyone have instructions for wiring up the high-voltage part of the system for someone with no high-voltage experience but a basic understanding of circuits etc?

    • Chris says:

      Hi NR
      What is your application? Where will the project be situated and in what type of enclosure? The high voltage side should be protected by a 30ma rcd somewhere in the system, the earth and neutral for each output come straight from the supply source (the plug/inlet) and go to your outputs. if you are using any metal in or outside of your enclosure then you should cross bond this to your earth. The live from your supply source should ideally go into 8 fuses ( rated at 10amps or less) then from each fuse you would go to the common terminal on each relay, I think the relay board you have is the same as I have, in which case I believe the middle contact on each relay is the common, you will then need to connect from the normally open or normally closed terminal of each relay (depending on if you would like the lights to turn off if triggered or to turn on if triggered) to each live off your outputs. I hope you can understand this and I will try to draw a circuit diagram and upload a link to it

      • NR says:

        Hi Chris,
        The project will be situated indoors. I haven’t quite found a good enclosure yet, I was thinking some sort of large plastic box. A circuit diagram would be extremely useful, thank you so much!

      • Chris says:

        If your lights are going outdoors you still need an rcd, I would recommend using one even if everything is indoors, I think a plastic abs adaptable box is the best way to house the bits, remember that the solder contacts on the bottom of the relay board are high voltage when powered up so make sure you use pcb standoffs or ensure they are mounted to something non conductive obviously, I do not have time now to make a circuit diagram but have taken a short video to hopefully help you out, mine is still an unfinished project and still needs a lot of work such as fuses inline as I state in the video, hope it helps any questions let me know http://youtu.be/byYf_-yoLMw

      • NR says:

        Thanks, that video is very informative. Are there any significant differences for “mains” power in the US (110/120 VAC) or is it the same configuration?

  13. plstearns says:

    I’m working on my box right now but I only need 4 outputs. Do I have to recompile or can I just change the lightorgan.c file?

  14. Kyle says:

    Can anyone provide me with a wiring diagram for the sain smart relay board?

  15. Pingback: Hallelujah! Raspberry Pi Lightorgan - Christmas Light Show | The Accidental Adept

  16. wynneth says:

    For everyone’s future reference, here is a (somewhat crude) diagram of wiring the Sainsmart 8 channel solid state relay board:


  17. togiles says:

    Thanks for the excellent post… became the starting point for my own project to make a Raspberry Pi light show. I moved away from just midi and went the route of taking the frequency response (via fft) of any mp3, wav, etc… thus enabling a light show created for any song.

    Thanks again for the initial inspiration and ideas to launch from!

    My code / project is available here for those interested in taking a peek, a few others have joined in and we’ve been adding other features like SMS voting for the next song to be played, Admin control via SMS, and more…:



    • Chivalry Timbers says:

      Wow togiles, that’s some amazing work! I’m glad to have inspired you, but clearly your idea and work are original in it’s own right. I will be trying your system, for sure! Also, I will add a link to your project on the main blog entry.

      • Todd Giles says:

        Sure … but it awesome to be able to learn from others that have already started down a similar path. You’ll have to share your experiences with our project after you play around with it — hoping it should work directly on your existing hardware!

  18. NR says:

    One more thing, I assume the easiest way to get power into the whole thing is like cutting open an extension cord and wiring the neutral and ground wires directly to the outlets and switching the hot wires with the relays. Is this assumption correct or am I extremely misguided?

    • I put an outlet in the inside of my box. I bought cord and a plug and powered the outlet from that cord. then I ran the power to the other outlets from that outlet box. This main outlet could then be used to power the pi and the amp. I’m assuming you know how to wire up outlets.

    • wynneth says:

      I did similar to Tim. I used a small power strip and 18 gauge electrical wire to wire from one outlet on the power strip to 8 electrical sockets I mounted on the front of my box. The power strip as well as the cord are all rated 15A max, and I’m primarily using some LED lighting with some incandescent – I’ve probably got less than 4A total running on it. Something I would recommend though that I did not do (yet) would be to isolate the power to the raspberry pi and any external power source of the relays from the power going to the lights, just as a precaution. My box is in no way up to code, but it’s run from inside the home with the cords to the lights protruding outside – here’s a photo of the mess: http://i908.photobucket.com/albums/ac286/wynn3th/Engineering/81E8E1B1-5997-4C7C-BFA1-629BE98CCF1D-13898-00000397B2559AD5.jpg
      It does all connect back to a properly grounded outlet.

  19. vierwout says:

    Is it possible to do this in combination with shairport?
    I would like to play music via Airplay and still have the awesome result as you.

    • NR says:

      That doesn’t sound possible, as I believe shairport plays audio directly to the system out. It is definitely not possible with Chivalry’s pi-lightorgan program, as that uses MIDI. If you could modify togiles’ program to accept a stream of some sort from shairport, then you might have a shot. But I think neither of the programs here are built for that, it is mostly for playing from an already existing file. You could make a web interface and control your lights from your iThing that way, though.

  20. KnC says:

    Thank you for a great Raspberry Pi project for the season. LightOrgan provided just the motivation to get us to put up lights.

    We used an idea found on YouTube to play an MP3 along side Lightorgan and just turn off Timidity… We used an open source midi editor on our Mac to customize the midi files and give us more control of the lighting. It turned out pretty good and with a little more work and more lights it should be incredible next year.

    QUESTION: if we put a header on P5 and wire the other four ALT2 GPIO channels, can they be used? I think our goal is to use 12 GPIO output pins and use 1 pin per note. This should make creating sequences from midi pretty easy to create from our keyboard…

    Yes, we have tape on the keys telling us what channels each note triggers. We just listen to the MP3 and hit the key corresponding to the pin (lights) we want to trigger. We didn’t have much time this year, but now we have 12 months to perfect our midi sequences. 😀

    BTW: SainSmart SSR boards work excellent. If you take a USB phone charging cord and feed the 5 volts to the relays instead of using the RPi’s 5 volts it works flawlessly. 😉

    Check out our psuedo blog of our 2013 Christmas Light Project at
    We provided pictures and videos of our adventure as well.

    Thanks again, and we look forward to seeing what others have done.

  21. KNC says:


    if we put a header on P5 and wire the other four ALT2 GPIO channels, can they be used? I think our goal is to use 12 GPIO output pins and use 1 pin per note. This should make creating sequences from midi pretty easy to create from our keyboard.

    if lightorgan is compiled with 12 channels, what will be the sequence? Since there are 12 notes in an octave we have tried to compile and use a test midi, but are tests are inconsistent with how they play… help. Are you using wiringPi’s GPIO sequence? instead of the physical pins?

    • Chivalry Timbers says:

      Hi KNC, thanks for your interest in the project.

      I believe that it should work given the properly crafted midi and lightorgan compiled with 12 pins.

      The wiringPI’s gpio sequence is used, you should check out gordon’s wiring pi guide for the numbering he uses.

      One thing that you might want to check is if lightorgan is filtering out certain notes because it considers them to be BASS or SYNTH or PERCUSSION type instruments.

      If you want to send me the midi file, I can try to debug the lightorgan code. Just shoot me an email.

      • KnC says:

        Haven’t had time to put a header on P5 yet, but we will post what we find. We are still using the older lightorgan.c. Just downloaded the new one, and checking out the file. Looks like you have been doing some playing. We were starting are first pin on pin 7. (GPIO4?), so that explains why our midi file was tripping channels 1,2,3,4,5,6,7,0 out of sequence.

        We have an idea to use CAT5 to send the GPIO signals to the relays, and use 3 different breakers to power our display. 12 channels for 1 octave Should be easier to sequence?

        Thanks again for the awesome program. We need to get more into programming, so we understand what is going on, but for the time being your work is awesome, and we are having fun blinking lights to our music. 😉

  22. Pingback: 12 Ways To Make The Most Of Raspberry Pi | DIGIZENS

  23. Pingback: Adam Ickes | Editing with a side of Raspberry Pi

  24. Pingback: 12 Cool Projects For Your Raspberry Pi

  25. Pingback: Raspberry Pi(ラズベリー・パイ)でここまで出来る!12のクールな使い方 | ReadWrite Japan

  26. Pingback: Techy Tenor | A tenor in search of tech

  27. Pingback: 12 tutorials for taking your Raspberry Pi to the limit | TopNewsSites

  28. How do I put background music in my Youtube video?

  29. Unknown says:

    Therefore, you will need to make sure that you understand your obligations being a borrower and browse every one of the fine print that the
    bank provides Unknown cash advances should basically be useful for serious situations.

  30. Pingback: Raspberry Pi Powered Christmas Lights | Alex K Projects

  31. Pingback: Haskins Arduino Fans | Raspberry Pi Lights: how to sync Christmas lights to midi audio | The Raspberry Pi and I

  32. Michael Iverson says:

    Can do this project without using a MIDI file? If so how? Or can I run a song through a MIDI File to make it work?

  33. Pingback: A la Découverte du Raspberry Pi | Espace Numérique Sciences Po

  34. Pingback: פטל מתוק יותר: גרסה חדשה למיקרו-מחשב Raspberry Pi | גיקטיים

  35. KnC says:

    Anyone figure out how to get either lightorgan, or lightshowpi working on a B+ with 12 channels?

    I am using pins 7,11,12,13,15,16,18,22,29,31,32,33
    I can get wiringPi (gpio) to access them in a bash script, but can not get either lightorgan, or lightshowpi to use the extra pins, or get the channels to play in the order I want.

    • KnC says:

      Big Ups to Chivalry Timbers for making a custom light organ version to work with my lightorgan/B+ setup! Going to be a bright Christmas at K-n-C’s house this year! 😀

  36. scifidba says:

    Is there a way to configure the Raspberry Pi to start playing music as soon as it is powered up? Also, will these relays work? http://www.amazon.com/SainSmart-8-CH-8-Channel-Relay-Module/dp/B0057OC5WK/ref=pd_cp_pc_0

  37. I have gotten timidity installed on my Raspberry Pi and I can run it as a server from the command line, but I’m having a hard time getting it set up as a Daemon. I’ve done a bunch of Googling, but the instructions I find are for other flavors of Linux and procedure seems to be different enough for Debian that I can’t quite bridge the gap. Would you point me in the right direction? I appreciate the help.

    By the way, I was tinkering with a project run by a Raspberry Pi when I found this article. I did a lot of other research before I finally bought the Pi, but it was this article that set me in motion. Thanks for that. Nice work on this.

    • wynneth says:

      jasoncmichels, there should be a timidity-daemon package in debian: sudo apt-get install timidity-daemon

      • THANK YOU! For the last couple of days I’ve been trying to adapt instructions where I edit scripts in /etc/init.d. It figures that it would be as simple as downloading another package. I just never thought of that. That got it working.

      • wynneth says:

        No problem. As for /etc/init.d/ I keep a template of a basic script I reuse for various scripts and programs all the time. A fairly decent sample with a nice little automation script someone wrote can be found here: https://gist.github.com/naholyr/4275302 (Take note though, there are a couple spelling errors you should correct, such as “retart” in place of restart.)

  38. Pingback: Weihnachtsgeschenk für Bastler und Computerfreaks

  39. steve says:

    I live in uk & got only a little knowledge of electronic parts .i been trying to do lights & music for some years .can someone give me advice on anything i need .
    Many thx

    • This list of materials for the project is pretty complete and specific. I think you would just have to adapt the list for the UK electrical standards.

      — The shape of your electrical outlets is different
      — You would want solid state relays that switch a 230 volt circuit, because that’s what you have coming out of your walls over there
      — The power adapters for the Raspberry Pi and the amplifier would convert UK power to 5 volts for the Raspberry Pi and whatever voltage the amplifier uses

      The input for the relays would be 3.3 volts or 5 volts because that’s what the Raspberry Pi is putting out.

      Then you would just plug in whatever lights you normally buy at the store.

      I am not an expert either, so someone else can check me on this.

      Good luck with your project!

  40. Lori says:

    But how did you do the wiring to the relay?

    • Tarcas says:

      One relay terminal should be fed by the hot (red or black) wire from your power cable. The other relay terminal will feed the hot (gold screw) side of your outlet. Repeat for as many relays and outlets as you’ll be using.
      As far as driving the relay, you’ll use Gordon’s wiring diagram to determine which pin number in code is which one on the hardware. My relays work fine at 3.3v (I think they’re rated for 2.8-5v, but I’m not 100% sure on that. I just know it includes 3.3v.) so I’ve just wired them directly to the Pi GPIO pins. If yours requires more than 3.3v, you’ll have to use transistors to switch whatever voltage you need (usually 5v or 12v) supplied from another source. Google and YouTube will help you there.
      Good luck!

  41. Bill says:

    Does anyone have step b y step instructions for installing all the software? I have the OS installed but had issues with getting all the software and python installed.

  42. Bill says:

    I need step by step instructions for installing the software. I can install the OS with no issues. Can someone help me with this?

  43. KnC says:

    Read thru the comments. There is good information. I recommend…

  44. KnC says:

    Finally got the RPi B+ configured and in the Christmas Pi Box… Built a satellite box with 4 channel relay. Works great…


  45. Bill says:

    Tried to install and make lightorgan and had issues.

    undefined reference to “snd_seq_open” and about 7 more similar lines.

    make: *** [lightorgan] Error 1

  46. venom says:

    im new to the life of pi and need help learning it and i wanna dive in for my first project christmas lights synced to music and i wanna have the pi do it all haha so i want the codes and music on card and power the pi web interface to turn on but ad in broadcast over fm the music so if you want to help me learn and build email douchebagitis@yahoo.com suject put pi thank you

  47. scifidba says:

    I have the lightorgan built. When I type in aconnect -o I only receive 0 ‘Midi Through Port0’ what do I do now?

    How can I have it play music when it starts up?

  48. Trey says:

    Is just a leading provider for 1000s of goods, businesses, and companies of rankings and independent opinions.
    Our aim, at, is always to supply precise and honest evaluations which are representative of
    the company in question. If for almost any explanation you are
    not pleased after your first session, we will enable you
    locate another instructor or refund your whole purchase.

    LVMPD sgt ofc T and DEBRA L WEBB. My rights were broke by DEWEY too.

  49. Pingback: Light Controller System Help – What should I use in my build to individually control multiple lights? | CL-UAT

  50. Pingback: Raspberry Pi — что можно сделать на основе «малинки»? - Медгаджетс

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s