arduino christmas lights documented by netman427

9
Arduino Christmas Lights Or How I took 2 months and 8 extensions cords to synchronize lights to music December 2013 - v1.0 Parts List Electronics Arduino board (and obviously the cables & software needed to make it work) Relay board Electrical outlet box outlets light switch wire (Romex is the name branded electrical cable) wire nuts & electrical tape Software Vixen 2.1 Arduino sketch Electronics Chances are if you’re reading this, you know what an Arduino is. If you don’t, this whole document will be of little use. You’ll need your Arduino IDE loaded and board connected ready for uploading sketches. (At least you should know where your stuff is. Again, I’ve betting wiring the electrical parts will take a while so connecting the board is not yet necessary.) There are two options for the relay board. You can build your own or buy a premade shield. I’m using a homebrew combination but I started with the Seedstudio Relay_Shield_V1.0 . It has 4 relays and mounts directly on the Arduino. Their documentation was ok but the example was poor. Basically it’s like any other digital output on an Arduino. You assign a digital PIN as output and set it high. This device has some extra features like wireless control using RFBee . This ultimately means you’re stuck both covering Arduino PINS you now cannot use AND trapped with their PIN configuration. Channels are as follows: PIN7 Channel 1 PIN6 Channel 2 PIN5 Channel 3 PIN4 Channel 4

Upload: geoffbernard

Post on 22-Oct-2015

134 views

Category:

Documents


1 download

DESCRIPTION

Christmas lights synched to music using an Arduino & Vixen Lights

TRANSCRIPT

Page 1: Arduino Christmas Lights documented by netman427

Arduino Christmas LightsOr How I took 2 months and 8 extensions cords to synchronize lights to musicDecember 2013 - v1.0

Parts List Electronics

Arduino board (and obviously the cables & software needed to make it work) Relay board

Electrical outlet box outlets light switch wire (Romex is the name branded electrical cable) wire nuts & electrical tape

Software Vixen 2.1 Arduino sketch

ElectronicsChances are if you’re reading this, you know what an Arduino is. If you don’t, this whole document will be of little

use. You’ll need your Arduino IDE loaded and board connected ready for uploading sketches. (At least you should knowwhere your stuff is. Again, I’ve betting wiring the electrical parts will take a while so connecting the board is not yetnecessary.)

There are two options for the relay board. You can build your own or buy a premade shield. I’m using a homebrewcombination but I started with the Seedstudio Relay_Shield_V1.0.

It has 4 relays and mounts directly on the Arduino.Their documentation was ok but the example waspoor. Basically it’s like any other digital output on anArduino. You assign a digital PIN as output and setit high. This device has some extra features likewireless control using RFBee. This ultimatelymeans you’re stuck both covering Arduino PINSyou now cannot use AND trapped with their PINconfiguration.

Channels are as follows:PIN7 ­ Channel 1PIN6 ­ Channel 2PIN5 ­ Channel 3PIN4 ­ Channel 4

Page 2: Arduino Christmas Lights documented by netman427

You can work around the blocked PINS bybuying a larger board, which is what I did.

Arduino Mega with USB host mode

I added an additional relay board to run channels 5­12. It’s a Saintek 8 channel I found cheap on Amazon.

Wiring ElectricalIf you are not comfortable with high voltage then STOP NOW!!! I’m not an electrician although I play one on theweekends. Even though I think enjoyable Christmas lights might be worth electrocuting myself for, you may not feel thesame. If in doubt, phone a friend. If they hang­up on you, read through this one more time and you may understand justenough to keep yourself safe…. or at least not dead.

(Since some countries use different wiring colors, this entire document is based on United States wire colors. Ifneeded, search for wire home outlet for your country to determine any differences. This stuff can kill you so I feel theneed to be over­specific.)

Standard home outlets are 110 volts and use 3 wires. Older homes use 2 but that’s not too safe. You’ll see why later.The three wires are white, black, and green corresponding to neutral, hot, and ground. Alternating current (A/C) is notthe same as direct current (DC) and cannot be thought of in the traditional sense of positive and negative.DC shown on the left is a constant flow of voltage while the AC voltage rises and falls over a certain time. In NorthAmerica, that time is 60 cycles/second or 60hz. Europe uses 50hz.

Page 3: Arduino Christmas Lights documented by netman427

If you think of the pictures as flow of voltage, the horizontal X axis represents the black or ground wire. The horizontalline labeled Vdc represents the red or positive side of the voltage flow. With alternating current, the voltage literally risesthen falls. Looking back at the diagram, the 0 displacement line (or X axis) represents the neutral or white wire. Thiscorresponds to a reference point from which voltage difference can be measured. Black carries the voltage and whiteprovides a return path for voltage flow. The ground wire was introduced as a safety factor. If for any reason a wirebecomes exposed, the ground wire provides a path for the electricity to flow literally into the ground of the earth.Electricity takes the path of least resistance and the ground cable provides that path. Without it, you’ll end up becomingthat path of least resistance and while being involved with circuitry is fun, becoming part of that circuit is not! Use avoltmeter to verify zero volts and don’t forget to check the plug if unsure.I found everything I learned so far about AC to be very fascinating and suggest doing your own research.The most important things to remember:

Green is ground and should connect to all switches & outlets. Green wire will only shock you if something is miswired or insulation is missing. Black carries voltage and is called hot or live. Do not touch! White is neutral and is the normal return path. While theory says it’s ok, I suggest Do not touch! Always hook up in the following order: GREEN ­ WHITE ­ BLACK Always disconnect in the following order: BLACK ­ WHITE ­ GREEN Don’t wire a circuit while it’s live. I use a powerstrip since the circuit breaker and switch provides a little extra insurance. Check your powerstrip is on before tearing apart a circuit to find out why it’s not working. Trust me on this.

Parts5­10ft cord with plug to be used for master power feed2ft 3 conductor wire to be used for jumper power feed5­10ft 3 conductor wire (or other sufficiently sized wire) for relay & outlet wiringlight switchoutlet boxwire nuts

Master Power FeedYou need to start with a three wire cord that will be used to feed power to the strings of lights. I would suggest using aseparate feed cable for each set of 10 or so lights. Just follow the same process for each feed cable and distribute thehot leg to the appropriate grouping of relays. I used an old cut from a vacuum cleaner. It has a hard rubbery plug, islong, well insulated, and thick enough. When power flows through a cable, both AD & DC will lose some voltage due toresistance. That resistance will show up as heat. You want cable thick enough to hold the necessary current (up to110V @ 15AMPs) but not be too resistant to flow. In other words, you should not use CAT5 network cable to carry110V but wire the thickness of jumper cables is a little overkill.

Page 4: Arduino Christmas Lights documented by netman427

Wiring FeedStart with your master feedcable (with plug), light switch,two outlet boxes, and thejumper feed wire.Strip the insulation from theoutside and then for all threeinner wires. Hook the greenwire to the green screw on theswitch. Hook the white neutralwire to the jumper power feedand secure with wire nut.Screw the black wire to theswitch upper terminal. (Hint:Twist the wire and put a smallbend to the right. When youtighten the screw, it will pull thewire around. Always makesure your wire is secure in the

plastic before tightening.) Add the black wire from the jumper feed cable to the bottom screw of the switch. The jumperfeed cable will now run into the second outlet box. The switch will allow you to turn off all lights while allowing yoursystem to run. It’s useful for replacing bulbs but makes me feel like I have *sigh* one more little piece of insurance. Iuse bare copper wire as ground wire in some places so green, copper, and ground wire are all interchangeable terms.

Wiring OutletsFor this, you’ll need an outlet box, outlet, 6 inches of black, white, green (or copper), and one other if you have it. I used4 conductor cable since it provides all those and uses red as the last color. You can use black for the second outletsince I suggest labeling all wires anyway.To allow each outlet to be switched separately, we’ll need to modify the outlet. Looking from the front, the tab on theright (hot) side will need to be cut. Once the tab is cut, hook the ground wire to the green screw on the outlet. Next,hook the white wire to the left side using the same wire wrapping technique. Hook the black wire to the top screw onthe right side and the additional color wire to the bottom screw on the right side.

Feed all wires through outlet box and label as follows: green ­ ground white ­ neutral black ­ hot #1 red (or black2) ­ hot #2

That bundle will be used to feed the first two channels. Repeat the same process for the remaining outlets but use thenumbers 3 & 4 in place of one and two. Make sure black is on the top of the outlet or your outlets will be backwards!

Page 5: Arduino Christmas Lights documented by netman427

Combining outletsNow, you’ll need some wire nuts and some green and white wire. Connect the green wires from the jumper feed wireto the green wires from each outlet box. Do the same for the white wire. Make sure the wire nuts are tightened. Addsome tape if you want to be safe.

Hooking to relaysYou’ll need one wire for each channel you are setting up and one black for a jumper. My 4 relay setup will need 5 total.Hook one to each common (COM) port on your relay board. Twist the other ends together and add the black jumperwire. Secure with wire nuts. Take the other end of the black jumper wire and hook it to the black wire of the jumper feedwire. Now you have a hot lead into each relay which will be used to send the hot leg to each outlet. Install the wire fromeach outlet (hot#1, hot#2, hot#3, etc.) to each relay normally open (NO) connection.

Double check your wiring. From the master feed wire, green and black should be hooked to the switch. Green, whitethen hook to jumper feed wire. Black should run out of switch on jumper feed wire. Green wire from jumper feed wiregoes into wire box and hooks to all outlet green wires. White from jumper feed wire goes into wire box and hooks to alloutlet white wires. Black from jumper feed wire hooks to wire that connects to hot channel feeds. Hot channel feeds goto each relay common terminal. Each individual outlet hot wire connects to the individual relay normally openconnection.

HardwareHere is where we hook the relays to the Arduino. If you use a relay shield, you can plug in and you’re good to go.Otherwise (or in addition) you’ll need to wire up a quick circuit to activate the relay. (I use this for the Saintek board.)

This circuit uses a 10k pulldown resistor toensure the transistor defaults to the offposition. The dot on the left side is will connectto a digital pin on your Arduino. The 2.2kresistor “throttles” the current from the Arduino5v output. The coil on the relay will connect to5v on one pin and to the “RELAY BOARDINPUT” marked on the graphic.When the Arduino pin goes high, it will activatethe transistor and give you a connection toground, allowing the relay to activate. Althoughthe Arduino provides 5v, use an external powerto supply the relay 5v.

Newer Arduinos have an internal pulldown resistor so you can eliminate the 10k one. The other parts should cost less than six or seven dollars.3.3 volt input should use 2.2k, for 5v, use 1k. You can use a 2N2222 or 2N4401 NPN transistor.

You’ll need one relay for each channel (or outlet) you plan to switch. Each relay needs an Arduino pin to drive it. I’musing a total of 12 channels, split across 2 sets of relays. 4 are on the Seeedshield and 8 are on a Saintek 8 port relayboard. The Seeedshield is pretty much plug & play. Assign pins 4­7 and you are done. However, it blocks alot of pinsthat I want to use. To access those, I ended up using a Seeed ProtoShield. I’m using 8 additional pins to drive NPNtransistors to provide ground using the above circuit.

Page 6: Arduino Christmas Lights documented by netman427

SoftwareThere are two parts to the software. Vixen lights to create the displays and Arduino code to listen for Vixen commands.

Arduino CodeThe Arduino code listens for data arriving over the serial interface and set the output channels appropriately. Best Iunderstand, Vixen just sends a series of bits corresponding to each channel you have configured. HIGHs (FF) andLOWs (00) are used to turn the channels on and off.

/* Arduino Vixen generic serial interface Based on code by smching (ediy.com.my) Modified by netman427*/

#define CHANNELS_COUNT 13#define Ch1 7#define Ch2 6#define Ch3 6#define Ch4 4#define Ch5 22#define Ch6 24#define Ch7 26#define Ch8 28#define Ch9 30#define Ch10 32#define Ch11 34#define Ch12 36#define Ch13 38 //LED for track beat indicator

int Ch[CHANNELS_COUNT] = Ch1, Ch2, Ch3, Ch4, Ch5, Ch6, Ch7, Ch8, Ch9, Ch10, Ch11, Ch12, Ch13;int incomingByte[CHANNELS_COUNT]; // array to store the values from serial portvoid setup() Serial.begin(9600);// set channel pins to output for (byte i=0; i<CHANNELS_COUNT; i++) pinMode(Ch[i], OUTPUT);void loop() if (Serial.available() >= CHANNELS_COUNT) for (int i=0; i<CHANNELS_COUNT; i++) // Serial.read processes one char incomingByte[i] = Serial.read(); digitalWrite (Ch[i], incomingByte[i]); // Write the Digital Output to the respective pin.

Open your Arduino IDE, load the above sketch and write to your Arduino.How does this work?

Create an array to hold the channel pins.Loop through the array to set the pins to output mode.

Loop to create a counter pointing to the current channel number.Set the current channel number (from array) to the incoming characterDo it again for each channel then start over for the first channel.

Page 7: Arduino Christmas Lights documented by netman427

Here is a sample of the data sent by Vixen. Note there is one column for each channel.

12­17­2013 02:45:49.353 [ 10] 00 00 00 00 00 All Off12­17­2013 02:45:52.119 [ 10] FF FF FF FF FF All On12­17­2013 02:45:53.462 [ 10] 00 00 00 00 00 All Off12­17­2013 02:45:54.822 [ 10] FF 00 00 00 00 Ch1 On12­17­2013 02:45:55.275 [ 10] 00 00 00 00 00 All off12­17­2013 02:45:56.181 [ 10] 00 FF 00 00 00 Ch2 On12­17­2013 02:45:56.431 [ 10] 00 00 00 00 00 All Off12­17­2013 02:45:57.431 [ 10] 00 00 FF 00 00 Ch3 On12­17­2013 02:45:57.681 [ 10] 00 00 00 00 00 All Off12­17­2013 02:45:58.900 [ 10] 00 00 00 FF 00 Ch4 On12­17­2013 02:45:59.134 [ 10] 00 00 00 00 00 All Off

In this example, I turned all channels on then all off. Next, each channel is turned on and off individually.

When the Arduino sees FF, it sets the pin assigned to the channel to HIGH. Double zeros (00) will set the pinLOW. To enable Channel1,4 and 5, it would look like this: FF 00 00 FF 00.

VixenNow that you know all that, it’s time to setup Vixen. There are two versions, stick with version 2.1. I think it’s simpler.http://www.vixenlights.com/downloads/vixen­2­downloads/. Once you download the program, unzip to a directory.

You can use the wizard, but I recommend against it. I think it’s better to have the trick explained before watching themagician do it. Therefore, here are the steps necessary to setup your hardware and create a sequence manually.

Create a ProfileProfiles defines your channels and what hardware you are using.Click Profiles ­ Manage.Click + to create a profile and give it a name. I suggest ArduinoSerial. The Edit a profile window will open.Click Add one channel until all your channels are added. (1 for each relay)

Once all channels are added, click Output plugins at the bottom.

Page 8: Arduino Christmas Lights documented by netman427

Select Generic Serial from the Available Plugins section, click ­­Use→ then select Generic serial Under Plugins in Use.Add your channels on the right side, then click Plugin Setup under the channel numbers.

For troubleshooting, you can include Event data logger. To get back here, click Profiles/Manage then double click your profile then click Output plugins.

Select the Serial Port your Arduino is on and choose 9600 for the Baud rate. Click OK to close.

Click Done to close through all windows to return to the main screen.

SequencesOk, so it’s all setup. How do I make the lights work? Once you have configured the plugin, you can test each channel…but not until you start to create a track. Select New ­ Standard sequence. Click create it. Now look in the top left andyou should see a checkbox next to the channel count.

Page 9: Arduino Christmas Lights documented by netman427

Test each channel to verify your setup.

Through a lot of trial & error (and suggestions), I found the easiest way to create a sequence is using a track beatindicator. You’ll use it as a reference point when creating sequences. I use a resistor soldered directly to an LED andone additional output pin. The other end goes to ground on the Arduino. If you are using 12 relays, this will become your13th channel. It’s assumed your sequence will be set to music, so make sure you have an MP3 file available.Associate the audio file with the sequence. Click Sequence then Audio. Click Assign audio to add an mp3 audio track.Verify Resize the sequence to the audio length is checked.

You now need to sequence the track beat with the audio. Vixen can play the audio and you use the CTRL key on thekeyboard to select when to activate the channel. For now, just do the beat track. Click on the channel you wish to usethen click play. Hopefully you can count music and find the downbeat of the song. Remember First grade and playingMary Had a Little Lamb on the recorder? You count 1­2­3­4­1­2­3­4. Hit CTRL for each count of 1. Don’t be confused withsongs like Jingle Bells. It’s 1­2­3­1­2­3. Just hit on what feels like the downbeat. You can pause, rewind, or start over if youneed to. Once you’ve done the whole song, click ok. You should now have a sequence with a steady pattern of boxeson Channel 13..

You can now create a simple pattern using the following method:On Channel 1, highlight in between the beat track. Hit enter to activate. (Should cover 4 squares)Repeat for entire song.Copy Channel 1 to Channel 2 and invert. To invert, left click and hold to select a section. Press t to invert.Copy Channel 2 to Channel 3 then remove the second & third boxes.Copy Channel 3 to Channel 4 then invert.Copy as you see fit. Remove and add cycles to change the pattern up.Remove and add marks where you want to cycle the lights and play around with different sequences.

You can now test it. Click the Check mark to start playing, sit back all your effort.