Arduino Home Automation
Control Heating and Lighting with an Arduino
Remotely controlling the lighting and heating in my house is something I have always wanted the ability to do. It's not very welcoming to come home after a weekend to a cold house. Leaving the heating on, even with a timer, is a waste as I don't always know what time I will arrive home. The ideal solution would be to remotely switch on the heating when I am about twenty minutes away from the house.
The Arduino is a flexible platform for building basic electronics projects. One of it's strengths is that there are numerous circuit boards which can be mounted onto the Arduino to extend its functionality.
The Ethernet Shield from nuelectronics.com is one of several boards which allow you to connect an Arduino to a network, using this setup to control some relays seemed like a good starting point.
WARNING: If you do not have experience working with mains electricity do NOT attempt this project.
Proof of Concept
Components for the initial proof of concept:
|Arduino Diecimila available from Maker Shed and other suppliers.||Ethernet Shield V1.0 for Arduino available from nuelectronics.com||Solid State Relays can be found on eBay, this FOTEK relay has a switched rating of 25-480VAC 25A and a control rating of 3-32VDC.|
Putting the proof of concept together took less than two hours, I wired up a mains socket through a relay and plugged a desk lamp into the socket. Using the web switch sample code from nuelectronics.com made it very easy to get the Arduino onto my home network and once I wired the controller connection of the relay to the Arduino I was able to switch the light on and off from my PDA. (UPDATE: This looks quite old now, obviously you can use an iPhone, iPad, Android device or whatever web enabled gadget you own.)
Modifying the Arduino Code
Before this could be connected up on a more permanent basis the Arduino code needed several enhancements. I found a modified version of the Ethershield library with a better TCP/IP stack which was put together by Andy, full details here. Using this library I modified the following:
- Added options boxes to the web page so that I could control multiple switches.
- Putting control of your lighting and heating on the internet would not be advisable without some form of security so I added a password to the web page.
- Added some timer code and a drop down list to the web page so I could specify how long a switch would stay on for.
The Arduino Diecimila with the ATmega168 microcontroller only has 1024 bytes of space to create and manipulate variables. With the help of PROGMEM, which is part of the pgmspace.h library, the strings for the web page are stored in flash memory instead.
Like most home internet users I don't have a static IP address so setting up a dynamic DNS is the next best option.
Initially I wasn't sure how I could setup dynamic DNS for the Arduino, I had thought about programming the Arduino to periodically call a dynamic dns service itself.
I had also read that some DSL routers can call a dynamic DNS service but the admin pages of my router didn't give any indication that this functionality was available.
After some searching I eventually discovered that my Netopia 2247 did indeed have a client for www.dyndns.com included in its firmware.
The configuration is only accessible via telnet but by following the instructions on page 262 of the Netopia Software User Guide V761 I got it up and running. (Unfortunately the link to the manual is now dead and dyndns.com have since changed their API)
Putting it all together
One of the most difficult aspects of this type of project is wiring up the various components around the house. There are x10 units which use the existing electric wiring and there are several wireless solutions. Unfortunately these can also be quite expensive so I decided to keep things basic for this phase of the project, I wired up one mains socket to power a lamp and then I wired up the heating system.
For the mains socket I used the casing from an old plug-in timer which didn't work any more, having it as a plug-in unit gives me the flexibility to move it around a bit. Once I removed the original circuit board from the plug-in timer, I had to carve away some plastic so that the relay would fit in, I drilled a small hole in the top to feed in two control wires and then wired the mains live connection through the relay. After some tweaking it all fit back together and was ready to be connected to the Arduino.
For the heating system I bought thirty meters of bell wire and ran it from my office/study up into the attic, across the attic, down the back wall, in through an air vent and finally into the gas boiler.
I have a Vokera gas boiler and although it is quite old I found the "Installation and Servicing Manual" on their web site.
This manual gave detailed instructions on how to connect external controllers to the boiler, these would usually be external timer switches or thermostats but connecting a relay would be no different.
There were some empty mounting holes inside the boiler control panel which conveniently lined up with the mounting holes of the relay. After connecting the relay to the boiler controller terminals and connecting the wire from the Arduino I did some testing before putting the boiler fuse back in, the LED on the relay let me know that it was working and once I put the fuse back in it all worked perfectly.
Using the System
I have been using this system much more than I thought I would. My initial plan was to use it to turn on/off a light when I was away from the house or to turn on the heating when I was on my way home. I actually use it most often when I am at home and when the timer has switched the heating off, I can turn on the heating for 10 or 20 minutes using my phone, tablet or laptop while I am working or watching TV without getting up to adjust the timer. Its really lazy and geeky but I still get a kick out of it!