loading

This project involves using a Raspberry Pi to drive 8 AC outlets which are connected to Christmas Tree light sets. The AC lights are simple one color strands of lights, but to give a more dynamic range to the light show there is also a 25 programmable RGB LED star. One of the benefits of using the Raspberry Pi instead of an Arduino controller is that I can drive the audio out of the Raspberry Pi to have the lights timed with music (not to mention the benefit having a WiFi connection to work on the software remotely).

Step 1: Materials

Keep in mind the materials below are what I used for this project. In many cases alternate parts/solutions can be used.

Here are the materials I used for this project:

For the controller:

  1. Raspberry Pi (B Model is what I used)
    • SD Card
    • USB Wifi Adapter
  2. SainSmart 8 Channel 5V SSR Module Board - Amazon
    • I avoided the mechanical relays as the clicking sound of the switch will be noticeably audible, and went we SSRs. This board is rated up to 2 AMP per SSR which is enough for powering a string of Christmas lights
  3. Jumper wires - Can be found cheap on Ebay
  4. JST SM Plug + Receptacles - Adafruit
  5. 32ft roll of wire (or four 8 ft pieces of wire)
  6. Extension Cord x 8
  7. Power distribution block x 2 - AdaFruit
  8. Power Strip
  9. Power Supplies
    • 5 Volts, 3 Amps or greater to drive LEDs and Pi
    • 5 Volts, 1 Amp or greater to drive SSR module
  10. Enclosure
  11. Speakers

For the star:

  1. 12mm RGB LEDs (Strand of 25) - AdafruitWS2801 chip in this product allows the Pi to just have to pulse the strand once rather than continuously pulse the line to keep the LEDs illuminated.
  2. Plastic ABS Sheet to hold LEDs in place - Walmart
  3. Lexan sheet to diffuse LEDs - Lowes
  4. Black Spray Paint
  5. White Spray Paint
  6. Wood

For the tree:

  1. White 100 light strand x 4
  2. White 50 light strand
  3. Red 100 light strand x 2
  4. Green 100 light strand x 2
  5. Blue 100 light strands x 2
<p>Has anyone come up with a faster way to make the timing files?</p>
Good evening how branch t Please order on son of raspberry and sainsmart or the + and - on relay out thank you
So here's my creation. I think I'm going to rotate the outlet bar 90 degrees not sure why I felt the current setup was the best route lol. That being said it's pretty clean. Need to tidy up the jumper wires to the Pi and cut down the house and encase it all . Thoughts?<br>
<p>Hi there! Great project. I'm just about finished my setup (just need to mount it and actually wire the relays to something (I bought outlets) Curious , how are you having the xmas.py run, are you doing it on a cron job every 10-15 minutes? I was thinking maybe I'd have a bash script that lights all of the relays up (gpio write 1) and then cron the python every 15 minutes or so. Is this how you did it too? Rather than having to login and do it manually</p>
<p>I have everything working except for the star. I am using the same Adafruit WS2801 leds as in the tutorial and am running Occidentalis v0.2 on a B+. I have double and triple checked my wiring and dont think thats the issue. Is there additional setup required on the Pi to control the star?</p>
I had the same issue, eventually I found a solution that had to do with something they changed in how the spi is handled. I followed instructions on how to disable this and it startrd working. Unfortunately i forgot to bookmark the page so I have no idea where to point you to.
<p>I found it! Thanks shundal1. You need to add &ldquo;dtparam=spi=on&rdquo; to your config.txt and reboot.</p><p>sudo nano /boot/config.txt</p><p>add&hellip;<br>dtparam=spi=on</p><p>&hellip;at the end of the file, save, and then reboot.</p>
<p>Phil,</p><p>I am having the same issue with getting the star to work. The first LED on the WS2801 strand lights up a light blue but nothing else happens. I have confirmed the wiring is correct, and also confirmed the Pi is connected to the input end of the strand. </p><p>Is there anyway of determining if the strand is damaged?</p><p>Any help is appreciated!</p><p>Thanks,<br>Jason</p>
<p>I actually had the same issue initially until I realized that the ground of the LED strand needed to be tied to the ground of the Raspberry Pi. One I did that the entire strip lit up. Not sure if you are running into the same issue with your wiring, but thought I'd throw it out there. </p>
<p>I tried tying in the ground as you suggested but I am still getting just 1 LED, and it does not change color when I run the programs. Here is a diagram of my wiring, I don't know what I'm doing wrong.</p>
<p>That is exactly what I am getting. I was about to contact Adafruit and see if I had a bad strip of LEDs. I am going to give Osprey's suggestion a shot and see if it helps.</p>
Has anyone had issues when attaching the LED star via the 8 ft extension? I have it working perfectly when testing, connecting dirrctly to the JST connector that plugs inti the Pi. However, when I connect using the long cable with JST connectors on either end, the star starts freaking out. It gets the right signal for the most part, but during blinks it flashes random colors and frequently gives the wrong colors.
<p>I'm on step 6 and 7 right now. I am only using 4 extension cords (with test bulbs on the end of them) so I powered each relay from one distribution block, and wired the extension cords to the other distribution block. I then used the other ends of the extension cords and wired them to the 4 relays. For some reason, the 4 extension cords test bulbs are not lighting up. Anyone have any suggestions? Thank you!</p>
<p>Did you figure out your problem I am having the same problem</p>
<p>Do you have power hooked up to the distribution blocks as shown in yellow in this picture?</p>
In test.py you'll see it lists out the channels as <br>11,12,13,15,16,18,22,7<br>but then in xmas.py it is pin_map array at the beginning that defines it as<br>11,12,8,15,16,18,22,7<br><br>So looks like my test.py and xmas.py don't quite line up. But all you need to do is change that 8 to a 13 in pin_map in xmas.py and sounds like it should work.
<p>Thank You Sir. That was an easy one! Now to tackle the start...!</p><p>Hey do you think you are going to program more songs for this coming holiday?</p>
<p>I think so. I know I wanted to Wizards in Winter by Trans-Siberian Orchestra last year but couldn't get to it, so that'll probably be at least one new one. Also I did manage to make an update to have the Christmas tree function as a grandfather clock, and gong with a simple animation on the hour, which I'll probably post when I take everything out for Christmas.</p>
<p>hi, thanks for the great instructions! any chance wizards in winter or another song is ready for this year?</p>
<p>Messed up my prior post..uggh</p><p>I enjoyed making this project and it works great. However, i can't get channel 3 to fire for any of the songs. I have verified it works by running a test.py program, but can't figure out in your code what the issue is. Any help would be very much appreciated.</p>
<p>I started reading through xmas.py and the pin_map array had &quot;8&quot; instead of &quot;13&quot;. I made the change and xmas.py is now triggering GPIO2/Channel 3. </p><p>Now, off to buy some more supplies so I can tie lights into the relay! </p><p>Thanks for such a fun project tutorial. </p>
<p>I'm working on testing my setup and I am having the same problem as Jason. I can run test.py and all 8 relay channel LED's light up in sequence. But when I run xmas.py with test.txt or the two songs, it does not light up Relay 3 (GPOI 2). The other 7 channels light up - and it looks awesome with the songs. </p>
<p>I am at the stage of connecting the Pi to the relay. I am using the same relay as in this tutorial, but am using a Pi2 B model. I can't seem to wire it properly. I have tried using the test program to try and get them to work through trial and error, however the LEDs on the relay for channels 1 and 2 are permanently on (I suspect due to my incorrect wiring). The way I have it wired now:</p><p>GPIO2 - Channel 1</p><p>GPIO3 - Channel 2</p><p>GPIO4 - Channel 3</p><p>GPIO5 - Channel 4</p><p>GPIO6 - Channel 5</p><p>GPIO7 - Channel 6</p><p>GPIO8 - Channel 7</p><p>GPIO9 - Channel 8</p><p>Then the GND pin on the relay I have connected to a GND on the Pi (Pin 30)</p><p>Any advice would be taken with widely open ears, thanks.</p>
<p>Which wiring diagram did you use to connect the relays to the GPIOs on the board? I had this issue and am wondering if you made the same mistake I did. Element 14's Pi2 diagram worked for me as the pin maps have changed over the models.</p>
<p>Yeah thanks, I used this diagram and got it working. I had to use a different test program as for some reason the one in this tutorial din't work for me. I edited the setup.txt to contain the pins I am using (35,37,7,29,31,26,24,21) and I did the same for the line in xmas.py (pin_map = ...). However, I am getting errors..</p><p>_________________________________________________________________</p><p>GPIO.setup(pin_map[i], GPIO.OUT)</p><p>Traceback (most recent call last):</p><p> File &quot;xmas.py&quot;, line 300, in &lt;module&gt;</p><p> GPIO.setup(pin_map[i], GPIO.OUT)</p><p>IndexError: list index out of range</p><p>_________________________________________________________________</p><p>I noticed someone further down had at least one of these errors, but any help on how to solve them would be great, thanks.</p>
<p>When I had this issue it was an issue with my songfile.txt. If you are using different pins then that is probably your issue. It is trying to work with the pinout provided by Osprey22 but those pins have been changed.</p>
<p>Question from an absolute newb here. Believe me, I know this is probably going to be easy to answer but I'm clueless.</p><p>What are you using to connect the terminal block to the GPIO? Just a jumper or electrical wire? If electrical wire, where do I get just a connection piece for the GPIO?</p>
<p>Its a jumper wire, the female connectors are the ones that connect to the GPIO. I got a set with all 3 possible configurations, just in case! http://www.amazon.co.uk/gp/product/B00L2X1X9Q?psc=1&amp;redirect=true&amp;ref_=oh_aui_detailpage_o00_s00</p>
<p>Has anyone found a faster way to write the sequence files?</p>
<p>What power supply did you use to power the relay, so that you had 2 separated wires that could be connected to the relay? I know it is a 5V 1A, and I assume AC-DC, as the relay takes DC. </p>
<p>You can use a normal Micro USB power supply. Just chop off the USB connector and strip the wire. Inside you will find 2 wires; red (+) connects to VCC and black (ground) connects to GND.</p>
<p>Can anyone explain the sequence files further? I see the format is TIME(MS),COMMAND,VALUE </p><p>I understand TIME is the position in the song. I'm assuming COMMAND represents the channel ? What does VALUE represent?</p>
<p>after your get rxmas.py running how do you stop it some you can do the music ones </p>
<p>Hope everythings fine for this first dancing Xmas in my house..</p>
<p>I made my first rookie mistake. I brought a 8 channel 5v mechanical relay instead of the SSR. It is very loud. Going to pick up a SSR next week and replace it. Thanks for that tip.</p>
<p>Perfectly awesome project; than you for showing us. My attempt however are falling short (I attribute it to my lack of an LED star ;) ).</p><p>I edited the setup.txt, test.py, and xmas.py mostly to reflect the pin order I'm using (xmas.py I edited pin_map to mine (5,6,7,8,9,10,11,12) and I had to change setmode(GPIO.BOARD) to GPIO.BCM because it kicked an error as such:</p><p>####################</p><p>sudo python xmas.py test.txt test.mp3 </p><p>Traceback (most recent call last):</p><p> File &quot;xmas.py&quot;, line 301, in &lt;module&gt;</p><p> GPIO.setup(pin_map[i], GPIO.OUT)</p><p>ValueError: The channel sent is invalid on a Raspberry Pi</p><p>####################</p><p>If I change it to BCM I get:</p><p>####################</p><p>sudo python xmas.py test.txt test.mp3 </p><p>Traceback (most recent call last):</p><p> File &quot;xmas.py&quot;, line 301, in &lt;module&gt;</p><p> GPIO.setup(pin_map[i], GPIO.OUT)</p><p>IndexError: list index out of range</p><p>####################</p><p>And all the lights/relays snap on.</p><p>I can't seem to find anything online about these errors (ValueError lead me to the BOARD vs BCM issue).</p><p>Since I am not using any RGB/LED lights would that cause an issue? Where am I forgetting to update a file to relate to my GPIO numbers? I just don't know. I'd love some help, once this works, I'm building my display for the front yard and going on a drinking binge while the kids and folks wonder around the neighborhood watching the shinny lights blink and bop.</p>
<p>Odd. I haven't kept up with the current revisions of the Raspberry Pi, but specifying GPIO.BOARD mode means that you are indexing by the actual pin number on the Pi. If in GPIO.BCM mode then you are indexing by the GPIO number. Take a look at the bottom of this page on the Raspberry Pi page</p><p><a href="https://www.raspberrypi.org/documentation/usage/gpio/">https://www.raspberrypi.org/documentation/usage/gp...</a></p><p>I don't know which version of Raspberry Pi you have, but what I would recommend is looking up a Pin Map with your specific board. </p><p>I stick with GPIO.BOARD because as the website above indicates, I can just physically count them. What I'm guessing is that the set of pin numbers you were using at the time of the error with GPIO.BOARD, it was trying to set a pin as a GPIO.OUT that is not able to be a GPIO.OUT like a fixed 3.3v or GND pin. </p><p>Just to double check, don't know how familiar you are with the Pi, but are you aware that not every pin can be GPIO? </p>
<p>I really appreciate you writing back so soon. I was up late last night and finally got it working (although my mp3 files are different than what you used; timing is off, I think I get enough of the idea to start tweaking/building my own).</p><p>I'll tinker with setting the pins (I ran &quot;gpio readall&quot; to find which ones are GPIO only and which are power, ground, etc..). Luckily even if I change it back to BREAD none of them are hooked up to anything but basic GPIO.# so I should be ably to keep tinkering and stop the errors.</p><p>Too fun already, hope I can get it all installed and up by Halloween! The longest part I think will be Audacity and writing the files lol .. thanks for giving us a few to play with in your Instructible.</p><p>Something the instructions aren't too clear on:</p><p>All songs run via xmas.py. Simply write your own timing file to go with your mp3 then run: &quot;sudo python xmas.py your-timing.txt your-song.mp3&quot; and enjoy the show. To run the random script just run &quot;sudo python rxmas.py&quot; and use ctl+c to kill it unless you run it in cron like Osprey's example.</p><p>Side note; also rxmas.py had the setup.txt in a location I didn't have, so it kept stopping. In the rxmas.py file it's mapped to /home/pi/xmas/setup.txt but in my case all these files are in /hom/pi/PiLights/ so I changed that to match mine and it seems to work well.</p><p>One thing I've failed to edit into Osprey's file is a way to reset all the pins to off (clear) after the script runs. It gets pretty bright when all the lights remain on (I think I'll have rxmas.py run after, just so there is something going on between songs).</p><p>Thanks again Osprey22, fun stuff!</p>
<p>Still working great but YES writing the *.txt files is an agonizingly long process (especially the farther you get into a song).</p><p>Does anyone have any ideas on how to incorporate this into PiFM similar to how LightShow Pi does it? (They are dead simple, but to me it looks like a bunch of lights blinking randomly and you try to make something out of it sub-consciously).</p><p>Also, I've noticed that sometimes the *.txt and *.mp3 will start at different times every few times you start them. Sometimes a significant portion of a second apart.</p><p>Thank you again; the promise is awesome on this one.</p><p>I included my build; With the lit installed setting on a stand, the inside with lid removed and the underside with the extension chord and 8 outlets exposed.</p>
<p>Great job! Nice</p>
<p>Well I got my RGB LED's in and finished my star. I picked up a 15 dollar star from Wally Wold and removed the lights it had and tie-stripped the RGB's to it. Worked out great. Got the RGB's on ebay for $20 so this put my project just under $100. I also used the Raspberry Pi B+ so I can add another 8 channels for next year and just tweek the txt file. If anyone is interested I am putting together an Excel spreed sheet that has a form added to it to allow an easy way to put together the music.txt file. all you have to do is enter the MS, select what command from a pull down and then enter the Value and it will enter a new line. This would time typing in all the Commands. I will post when I have it done.</p>
I also would like to use your excel file could you send to me too please.
I never got around to doing it. I came across Vixen lights and found that they have a very good program that does everything I want to do. This project was a good start for me to get familiar to this type of thing and now I am going bigger.
<p>What software did you use on the Pi? Raspbian, or I've seen people talk about FPP?</p>
<p>Thank you, I will check it out., Good luck with the bigger project.</p>
<p>How big is this star? I was looking at a few on Amazon. Trying to figure out how to get 24 leds in a 10 light frame. I don't feel like getting into building a frame! Also, the Excel sheet would be appreciated.</p>
I think it was about a 12 inch star at Walmart. It had a translucent film over both sides and was two half's tied together. I took it Aprt carefully an strapped my RGB's in the same pattern as the instructions say on this project. It was a tight fit but looked great.
<p>Can you explain Step 6 a little more?</p>
<p>Sure, perhaps let me explain it differently by following the path of electricity. It's Alternating Current (AC) but let's just pretend it's flowing in one direction for now:</p><p>So electricity comes from the power strip, through one of the two prongs in the AC plug into the bottom distribution block. Then from there it goes to the relay board terminal for channel (blue highlighted wire in the step 6 pic) then from there it goes to the other end of the relay terminal for that same channel and onwards 8 feet to the end of the extension cord where you plug you lights in. Then on the trip back it is going to the upper distribution block and back to the other prong of the AC plug into the power strip.</p>

About This Instructable