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.
TweetingXMasTree.eps261 KBStep 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."
Xmas_Tree.pde998 bytesStep 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:
python twitter_xmas_code.py
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:
#red
#green
#white


























































































Visit Our Store »
Go Pro Today »




As a side note, take a look at the "ADC and digital I/O line support" 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.
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.
However, that's all splitting hairs. The project works, it's very well documented, and the photos are clear and plentiful. Nice writeup!
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.
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.
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.
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 :)
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.
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.
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.
Ground - Your "major concern" 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 "strongly recommend installing one", please explain why.
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.
Polarity - You stated "110v on a neutral will destroy...some equipment..."
*** This is 100% dead WRONG ***
There would not be a single piece of electrical equipment that would be harmed by having its neutral and "hot" 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 "neutral" is because it is electrically attached to ground at the distribution source that provides power to the building. The purpose of "bonding out" 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.
Fuses - 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.
My apologies for the long post, but people need accurate information when dealing with electricity.
VERY nice instructable by the way - well thought out and well documented with excellent pictures. A pleasure indeed. ~Dave
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.
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.
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 "2A Protection"
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.
The polarized plug is just for people's safety. Since people are referenced to ground, neutral is safe at 0 volts to us while hot is dangerous at between +110 and -110 volts. 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.