Introduction: Christmas Tree Lights Controlled by Phone? a Simple Internet of Things Hack.
My son wanted to be able to turn the Christmas Tree on and off with his phone. We dug around in the Secret Mountain Laboratory (AKA the basement) and
Introduction: Christmas Tree Lights Controlled by Phone? a Simple Internet of Things Hack.
My son wanted to be able to turn the Christmas Tree on and off with his phone. We dug around in the Secret Mountain Laboratory (AKA the basement) and came up with the following project, which uses an Arduino to smarten up a dumb infrared remote-controlled power socket and make it controllable via a web interface within our home network. While this example uses a set of Christmas tree lights, this is a super-safe way for kids to learn about using the web to control any appliance: by interfacing with a remote control we don't need to mess around with mains electricity.
If you can use a soldering iron, copy and paste code, and you've got an internet-capable Arduino, with a couple relays you can turn a set of cheap remote-control power sockets into nodes on the Internet of Things. We built this entirely with things that were lying around, except for the relays, which cost 4 bucks.
What we used:
- Arduino Uno & 9v Power source
- Adafruit CC3000 Wifi Shield
- SainSmart 5v 2-Channel Double Relay
- Cheap Remote-Control Power Sockets (If the remote has an LED to confirm button-press, that can be a huge help when testing)
This project uses the Arduino aREST library written by Marco Schwartz, an awesome bit of code that allows the Arduino digital pins to be directly addressable via web calls, e.g. http://192.168.0.15/digital/7/0 [Sets Digital Pin 7 LOW] and http://192.168.0.15/digital/7/1 [Sets Digital Pin 7 HIGH].
Bear in mind that this setup only works within a home network on devices using the same WiFi or ethernet: your arduino, your webserver hosting the page, and the phone or other client device that visits the page all have to be in the same digital neighborhood and able to visit local IP addresses.
The final ingredient is a locally-hosted web page with big ugly ON OFF buttons designed by my 10 year old (User Experience and web design can wait, this is SCIENCE!). By calling up the webpage on his phone, he can turn the Christmas Tree lights on with a wave of his iPhone and a shout of "LUMOS!"
Step 1: Hack Open the Power Socket's Remote Control
We used a cheap remote control mains socket kit we had lying around. Ours had four sockets and one Remote Control, with each socket having a dedicated On and Off button on the remote. We only used one of the sockets, but a more ambitious project could use the same method here and more relays to create multiple smart nodes. The look of your remote may be different, but the principle of this is pretty straightforward.
Look hard at the remote control for your power socket. There's a way into it. Might be a screw, might be a matter of prying it apart with a butterknife. Lift the faceplate off, and remove any fastening screws so you can get at the back of the circuit board.
For each button you want to programme, you want to identify the two solder points -- mine were on the backside of the board -- that the button connects together when pressed. If you have an LED on the Remote that makes things easier: you'll see it go on when you put a jumper wire between the right points. (If there's no LED, you can just plug a light into the socket you're trying to control and use that to test.) Solder a loose wire to each of those points. When you complete the circuit by touching these wires together, the remote LED should go on and the power socket respond: you're basically replacing a mechanical button press with a circuit completion.
Step 2: Wire Up the Relay and the Arduino
We used an Arduino Uno and an Adafruit CC3000 WiFi shield, but this project will work with any internet-connected Arduino, be it the YUN or another Arduino flavor with an Ethernet shield.
In the case of the Adafruit shield, you need to be careful not to use any of the pins that it uses for dedicated board functions. I used pins 9 and 10 in my first attempt at this project, and couldn't figure out why the 10 pin seemed to be randomly going high. That would be because I didn't Read The Fine Manual that cam