It's Christmas season once again and that means its time to get together with all of your friends and family to share in the joys of the holiday spirit. In past times, with all of the food, drink and merriment, it has been easy to get too lazy to get up off the couch and change the tree's lighting. Fortunately, we are living in the modern era, and this no longer needs to be a problem. With the assistance of our good friend, the Arduino and a Twitter-enabled cellphone, you can now update the tree as you slouch in a food-induced coma on the couch. Simply tweet the colors you would like to see lit and the tree will light up like Christmas magic.

Step 1: Go Get Stuff

You will need:

- (x2) Arduino Uno
- (x2) Wireless SD shield
- (x2) XBee transceivers
- 8 x 6 x 3 project enclosure
- Laser cut panel (file) ***
- (x4) sockets
- 12 awg stranded wire
- 22 awg red and black solid core wire
- (x1) Multipurpose PCB
- (x4) 9V relay (2A @ 120V)
- (x4) 2N3904 transistors
- DPDT rocker switch
- 9V battery connectors
- 9V battery
- 9V battery holder
- M-type power plug
- Lamp cord
- Wire nut (large enough to hold five 12 awg wires)
- (x4) 6-32 x 1/2"
- (x4) 4-40 x 1-1/2"
- 4-40 x 1/2"
- (x4) 6-32 nuts
- (x5) 4-40 nuts
- (x4) adhesive rubber pads (optional)
- USB A/B cable
- A computer

*** If you don't have a laser cutter, you can use a cutting service like Ponoko or print out the file and use it as a cutting guide for making the panel with more traditional tools.

Step 2: Assemble Arduinos

Place the wireless SD shield onto the Arduino.

Next, place the XBee transceiver into the socket of the the wireless SD shield such that the antenna is closer to the edge of the board.

Step 3: Wire the Outlets

Attach a 12 gauge wire to each power terminal of the power sockets.

Don't worry about attaching the socket's ground terminal to anything since standard stranded Christmas lights are not grounded.

Step 4: Fasten

Fasten your power sockets to the front panel using nuts and bolts.

Step 5: Drill a Hole

Drill a 5/8" hole for the lamp cord cable centered on the lower edge of one of the shorter side's of the case. In other words, copy what has been done in the pictures.

Step 6: Knot

Pass the lamp cord cable and tie an overhand knot to prevent it from being pulled back through the hole.

When you finally commit to tying the knot, don't forget to leave about 6" of power cable inside the case to work with.

Step 7: Wire Nut

Bundle together a corresponding wire from each of the power sockets. In other words, they should all come from the identical terminal of each of the power sockets.

Strip the ends of each of the wires if you have not done so already.

Take one of the wires from the lamp cord. Bundle that with the four wires.

Twist the wire nut firmly onto the wires until they are all securely held in place.

For a little extra protection, I zip tied the bundle of wire directly below the wire nut.

Step 8: Mark and Drill

On the inside of the case, place your perfboard and make a mark inside each of its mounting holes.

Next, place the Arduino in a position in which you will be able to plug and unplug your USB cable (once it is affixed to this position). Repeat the process.

When all of the holes are marked on the bottom of the case, drill the circuit board markings using a 9/64" drill bit and the Arduino markings using a 1/8" drill bit.

Step 9: Build the Circuit

The Arduino operates at 5V, but the relays operate at 9V. To be able to use the Arduino with the relay, it is necessary to use transistors as controllable switches. When the Arduino pin goes high, the transistor lets 9V from the battery power supply flow through the relay coil, which in turn provides wall current to the socket connected to that particular relay. When the pin goes low, the relay is deactivated and the socket disconnected.  In this way, it is possible to turn on and off each of the sockets.

Build the circuit as specified in the schematic, but do not yet worry about Arduino, socket or power connections.

Step 10: Socket to Me

Attach the sockets to the N.O. pins on the relay. This is the pin that is not connected when no power is applied to the relay.

Make sure that you note which socket is going to which relay. I solved this problem by labeling the relays from one to four, where one stood in for the socket on the leftmost side of the panel and four was on the far right.

Finally, tie together all of the common pins from all of the relays with the one remaining lamp cord wire. I accomplished this easily by bridging these connections with the common rail on the circuit board and then soldering the lamp wire to the rail.

Step 11: Mount

Pass your  6-32 x 1/2" bolts up through the bottom of the circuit board.

Inside of the case, place the 1/4" spacers onto the bolts.

Put the circuit board on top of the spacers, and then fasten it in place with the nuts.

Step 12: Power Switch

Pick one of the outer terminals pairs to solder the power connection to. Solder the red and black wires from the 9V plug respectively to each of the terminals in this pair.

Connect a 5" red and black wire to the center pair such that they line up in color with the 9V clip.

Take apart the M-type male connector and slide the protective covering on the wires.

Solder the red wire to the center terminal of the plug. Solder the black wire to the outer barrel terminal.

Twist the cover back onto the plug to hide and protect your soldering.

Step 13: Drill and Mount

On the side of the case opposite to where the circuit board and Arduino is suppose to mount, mark and drill a 3/4 " hole using a spade bit.

Using the switch's mounting hardware, install the switch into this hole and fasten it firmly in place.

Step 14: Attach the Arduino

Mount the Arduino to the inside of the case using the 1-1/2" bolts and corresponding 4-40 nuts.

Step 15: 9V Clip

Lastly, drill a hole in the bottom of the case in a spot where there is a lot of free space using a 1/8" drill bit.

Fasten the 9V clip into the inside of the case by passing the 4-40 x 1/2" bolt from the inside of the case out. Unlike mounting the relay board and Arduino, the nut should be fastened on the outside of the case.

Step 16: Program

Plug in your USB cable, make sure that the switch on the Wireless SD board is toggled to "USB" and program the Arduino with the following code:

When you are done programming it, unplug the USB cable and toggle the switch back to "micro."

Step 17: Connect

Plug in the wires from the relay board into the female headers on the Arduino board as follows:

Relay/Socket 1 --> Pin 3
Relay/Socket 2 --> Pin 4
Relay/Socket 3 --> Pin 5
Relay/Socket 4 --> Pin 6

Relay coil --> Vin**
Ground --> Ground

**Note that if you find that the Arduino Vin pin is not supplying enough power, you will definately get better results by soldering this wire to the red wire on the power switch that is soldered to the M-type plug (do not connect it to the red wire connected directly to the battery).

Step 18: Plug It In

Plug the M-type connector into the Arduino and connect the 9V snap to a 9V battery.

Place the battery snugly into the battery clip.

If the light on the Arduino does not turn on right away, try pressing the power switch. It should light up now.

You're now mostly done. Power it down to conserve energy.

Step 19: Case Closed

Fasten the socket panel firmly in place to close the case.

Step 20: Add Pads (optional)

A nice finishing touch to the controller box is to add an adhesive rubber in each corner on the bottom of the case.

Step 21: Setup Python

Before you can go any farther, you need Python.

If you are using a Mac with a recent version of OS X, you should have Python already.

Open the Terminal, type into the command prompt "python" and hit "enter."

This should open up Python.

To see Python do something type the following and then press enter:
print 'hello world'

This will return "Hello World" in the prompt.

To quit Python hit "control-D".

If you don't have Python, you can go download it from python.org and follow the instructions to install.

Step 22: Dependencies

In order for the python script to be able to talk to Twitter and read from the serial port, you are going to need to download and install a series of "packages," which is the Python name for code libraries.

The packages you will need are:
There are instructions for download and installing all of these packages on each of their respective pages.

Keep in mind that simplejson, httplib2, and python-oauth2, are all required for the python-twitter package to work. So, even though we don't specifically call to import in the code, the program will not run properly without them.

Step 23: Setup Twitter API

The next step is to get authorized to use the Twitter API. Go to the Twitter app developer page and enter the account you have created for you Christmas Tree (if you have not done so yet, now would be a good time).

The Twitter app developer page is optimized for people building apps around twitter for other people to use and not people making Christmas Trees responsive to tweets. Fill in the application as best you can.

You will end up at a page which will display a "consumer key" and "consumer secret" number. Below these numbers you will see something about "Your access token." There is probably currently nothing there except a button that says "create access token." Press this button. There now should be two long strings of gibberish labeled "access token" and "access token secret."

Keep this webpage open. You will need to copy and paste these four numbers into your code.

Step 24: Connect Transmitter

Plug in the other Arduino into the computer. Don't worry about programming it. It functions mainly as a pass-through for transmitting serial data.

It is important to make sure that the small switch on the top of the SD wireless shield is set to "USB"

Step 25: Python Script

Attached below is the python script that checks twitter and sends serial commands to the tree. Download and open this script in a basic text editor. Once downloaded, you may need to rename this file to: twitter_xmas_code.py

Note where in the code it says:

api = twitter.Api(consumer_key='consumerkeyhere', consumer_secret='consumersecrethere', access_token_key='accesskey', access_token_secret='accesssecret')

Copy and paste the codes from the Twitter app page into the body of your code as specified.

Also, note where it says:
ser = serial.Serial('/dev/tty.copyandpastefromArduinoIDE', 9600, timeout=1)

Replace "copyandpastefromArduinoIDE" with the name of the serial port selected in the Arduino programming environment. You can find this by selecting the "Tools" option from the top menu and then looking at what is checked under the "Serial Port" menu (note the Arduino must be plugged in for the serial port to show up).

After modifying the code, don't forget to save your changes.

Next, open your computer's terminal, and navigate to the directory your python script is in.

Finally, type in the following and press enter:

python twitter_xmas_code.py

Your script should now be running. Leave the terminal open.

Step 26: Plug Everything In

Plug the Christmas lights into the controller box. Make sure you have the right colors plugged into the right sockets. You may want to label them so you don't forget which is which.

Finally, plug the controller box into the wall.

When you are ready to get going, toggle on the power switch on the controller box.

Step 27: Tweet

To change the colors tweet at the tree.

You can currently control the tree by tweeting the following color commands:

Very interesting project. I started to do something like this with battery powered xmas lights, freebasic. twidge, and the parallel port, but had other projects to work on. .
could you put in the arduino code.<br>
See step 16
(I'm posting this separately from the other comment so that the resulting threads are separate.)<br><br>As a side note, take a look at the &quot;ADC and digital I/O line support&quot; section of the XBee manual. The XBee could drive the transistors directly, making the Arduinos in this project entirely superfluous. The PC-side program would simply have to place the units into API mode and send the appropriate Dx commands. <br><br>Although if your PC doesn't have a UART (I see in the photo that it's a modern Mac), then using an Arduino as a USB-to-serial converter is a practical, albeit expensive, way to do it.<br><br>However, that's all splitting hairs. The project works, it's very well documented, and the photos are clear and plentiful. Nice writeup!
I'm concerned that the lack of snubber diodes on the relay coils means bad things for the drive transistors and potentially the Arduino itself.<br><br>Relay coils, like all coils, are inductive. When you place voltage across a coil, current starts flowing through it, building up a magnetic field in the coil. When you remove the source of current, that magnetic field tries to collapse, but the energy in the field has to go somewhere. It forces the current to continue flowing until the field is dissipated, raising the voltage if necessary. This effect is how switchmode power supplies work.<br><br>If you've turned on the current with a transistor, then when you turn the transistor off again, the voltage will spike until the transistor conducts anyway, damaging the transistor. Your circuit might endure a thousand on-off cycles before anything obviously bad happens, or it might smoke right away. When the transistor fails, the rest of the energy might get dumped into the Arduino.<br><br>To prevent this, put diodes in parallel with the relay coils, but orient them so that they're not normally conducting. When the coil de-energizes, the inductive kick is opposite in polarity, and it will flow harmlessly through the bypass diode, rather than beating up the transistor. It's essential to provide this free-wheeling diode on every relay or solenoid coil! Motors exhibit the same effect, btw.
I love it! You should probably put a 1k ohm resistor limiting the current to the base of each transistor.
hey everyone post your tree's twitter handle so i can wake up on xmas and turn all your lights off/on/nutty
Awesome project, looks really neat and professional. Ive wanted to do something like this for years, but never thought of twitter integration. Truly ingenious, and much beyond my abilities, very good work. <br><br>However being an electrician, I just want to warn you of a few things. Your connections on the receptacles need a stak-on connector because their stranded (although that will work fine assuming no strands are moving around) but my major concern is the lack of a ground. Sure Christmas lights don't have them, but you never know what could happen, and I strongly recommend installing one. Or install receptacles that don't have a ground prong. And because your plugs are polarity specific, check your lines coming in. 110v on a neutral will destroy (sometimes violently) some equipment (as I learned when I modified a string of LED lights to fit in a non polarized plug, not pretty) Also, because you have 20A T-Slot receptacles, an your relays are only good for 2A, I recommend a 2A fuse for each plug, just to protect your kick ass project :) <br><br>I was also wondering why you opted for a 9V battery instead of an actual power supply such as a wal wart? It wouldn't be hard to place the transformer inside of the project box and connect 110v to it in there, so you still only have a lamp cord. <br><br>But Very good instructable. You covered every step thoroughly and made it easy for anyone to build this (which I'll be doing soon :)) keep the good ideas flowing and stay safe this Christmas.
<strong>@bobrigewitch</strong>&nbsp; When someone states that they have credentials in a certain area, it implies that the information they give is accurate and truthful. Since your post contains incorrect advice regarding electricity, I am compelled to respond to set the record straight.<br> <br> I happen to be an electronics engineer with electrical certification and 26 years in the industry. I will be as brief as possible, and will discuss only three of the assertions.<br> <br> <strong>Ground</strong> - Your &quot;major concern&quot; with the project not having a ground is unfounded. Many appliances and consumer goods do NOT have a ground, toaster, coffee maker, shaver, vacuum cleaner etc. As you pointed out, the Christmas lights have no ground - there is absolutely no benefit or added safety from including a ground. Since you &quot;strongly recommend installing one&quot;, please explain why.<br> <br> Do you know why the ground pin is longer than the two flat blades on a 3-prong plug? It's so that the equipment's safety (ground) is last to be disconnected when unplugged.<br> <br> <strong>Polarity</strong> - You stated &quot;110v on a neutral will destroy...some equipment...&quot;&nbsp;&nbsp;&nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <strong>***</strong>&nbsp; This is 100% dead WRONG&nbsp; <strong>***</strong> &nbsp;&nbsp;<br> There would not be a single piece of electrical equipment that would be harmed by having its neutral and &quot;hot&quot; terminals interchanged. With Alternating Current (AC) the polarity of plus-minus or positive-negative, is swapped back and forth 60 times per second. The only reason one terminal is designated as &quot;neutral&quot; is because it is electrically attached to ground at the distribution source that provides power to the building. The purpose of &quot;bonding out&quot; the neutral like that is purely for safety. Outlets/plugs with the larger slot/pin is to preserve this safety feature by creating a polarity scheme. For instance, a light fixture would have the shell of the socket connected to neutral in case someone's fingers touched the metal threads on the base of a lightbulb, in case the power was still on while changing it. Not all electrical devices make use of the polarity feature (it's optional) and you'll still see many plugs with same-sized blades. Polarised plugs are becoming almost the standard now, but that has more to do with plug fabrication reasons rather than the product's electrical requirement.<br> <br> <strong>Fuses</strong> - I do agree that 2A fuses would be handy for each outlet, but the reason is entirely for the protection of the 2A relays, NOT because of the capacity of the outlets. Again, MANY household items do not contain fuses (toaster, vacuum, lamps), but many electronic devices do in order to protect ultra-sensitive circuitry, but those are not replaceable by the user.<br> <br> My apologies for the long post, but people need accurate information when dealing with electricity.<br> <br> VERY nice instructable by the way - well thought out and well documented with excellent pictures. A pleasure indeed.&nbsp;&nbsp; ~Dave
I thank you for your criticism, I guess I wasn't clear enough on a few things, allow me to explain. <br><br>Ground - My concern with ground is that some appliances use a 3 prong plug, and those appliances have a ground because the engineer who designed it felt it should have one, and since his plugs have a 3 prong receptacle, it is possible that these grounded appliances would be plugged into this unit, therefore there should be a ground to accommodate for these circumstances. <br><br>Polarity - I agree 110v on the neutral and 110v on the hot will result in 0v potential, however incorrect polarity would mean there would be 110v on the neutral and 0v on the hot, resulting in 110v that is reverse bias. They design polarized plugs (one blade wider than the other) because some equipment can be harmed from this situation. <br><br>Fuses - your right, they would be more for the protection of the relays, however that directly corresponds to the load that can be placed on the relays. My idea was just &quot;2A Protection&quot;<br><br>I am new to this site and just thought I'd help. Also next time allow me time to defend myself instead of bashing my knowledge Dave. Merry Christmas. <br><br>
Actually, in AC, polarity doesn't matter to the circuit.&nbsp; AC is constantly switching polarity.&nbsp; The best way to describe it is to use the physics concept of &quot;frame of reference&quot;.&nbsp; A person's body is usually grounded.&nbsp; This means any voltages are relative to, or referenced to, ground.&nbsp; This means that to us it seems neutral is 0 volts and hot switches back and forth between 110 and -110 volts.&nbsp; The appliance is not referenced to anything, so to it, one wire is 110 volts higher than the other, and then they switch with each other.&nbsp; It doesn't know which is hot and which is neutral.<br> <br> The polarized plug is just for people's safety.&nbsp; Since people are referenced to ground, neutral is safe at 0 volts to us while hot is dangerous at between +110 and -110 volts.&nbsp; This way, engineers can make sure it is much harder for people to come into contact with hot wire than the neutral one since they know which will be zero volts relative to the user.
I guess your right there. Thanks for the clarification. Although my 'why' is wrong being sure of correct polarity still isn't a bad idea.
It totally says that this was submitted by radioshack on the great create website!
Very nice!
Sweet project as usual. I'm curious, why 2 arduinos and python rather than an ethernet shield or wifi shield. Also, thanks for using alot of easily accessible RadioShack parts. I'm kinda thinking that's why 2 arduino and a computer.
I tried to stick with easily accessible Radioshack parts ;-)

About This Instructable




Bio: My name is Randy and I founded the Instructables Design Studio. I'm also the author of the books 'Simple Bots,' and '62 Projects to ... More »
More by randofo:Circuit Board Projects Octave Up Pedal Spooky Whispering Prank 
Add instructable to: