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
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
Don't worry about attaching the socket's ground terminal to anything since standard stranded Christmas lights are not grounded.
Step 5: Drill a hole
Step 6: Knot
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
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
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
Build the circuit as specified in the schematic, but do not yet worry about Arduino, socket or power connections.
Step 10: Socket to me
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
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
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
Using the switch's mounting hardware, install the switch into this hole and fasten it firmly in place.
Step 14: Attach the Arduino
Step 15: 9V clip
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
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
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 20: Add pads (optional)
Step 21: Setup 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 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
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
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
You can currently control the tree by tweeting the following color commands: