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
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
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
Note where in the code it says:
Copy and paste the codes from the Twitter app page into the body of your code as specified.
Also, note where it says:
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:
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: