Google+

Wednesday, 14 August 2013

Home Automation (or Robot Butler called Geoffrey) - iPhone controlled, arduino based








Being able to control everything from your pocket has long been a dream shared by many.
These days, almost everyone has a smartphone in their pocket, why not use that?

So that's what I did.




I can now control electrical sockets and the main lights in my house using my iPhone. It's all totally wireless and you can set up smart run-times within it (e.g. when you press the shower button it will turn on the boiler, the bathroom lights and the upstairs lights, after 1 minute it'll turn off any downstairs lights that are still on and then after two minutes it'll turn off the upstairs lights, and after 20 minutes it will turn off the bathroom lights).

By using basic electrical knowledge, taking apart some readily available items and writing some arduino code you to can make yourself a robot butler (mine's called Geoffrey).

Let's get started!




Step 1: What you'll need


Tools you will need:
• Knife or other flat blade
• Stanley knife
• Set of standard Phillips and crosshead screwdrivers
• Safety Torx T15 screwdriver (can be done with a standard Torx T15 but more faff and potential breaking of a flat head screwdriver may ensue)
• Soldering iron
• Solder
• Wire cutters
• Wire strippers (although this could be done with a knife)
• Multimeter

Materials you will need:
• An arduino (I’m using an Arduino Uno)
• An arduino Ethernet shield
• A RTC (real time clock) module. Adafruit do a very good kit that I'd highly reccomend (http://www.adafruit.com/products/264) but if you search for "New I2C RTC Real Time Clock Module DS1307 Arduino" on eBay you will probably find one for a fair bit cheaper (that's where I got mine)
• A set of RF plug sockets and remote. I used Maplin's Remote Controlled Mains Sockets (product code N79KA). The RF module used in these plugs is the only one I’ve coded for and as such the only one that this has been tested with. There are plenty of other brands that use the same chip (SC5262) but you will need to check this for your individual sockets. If you can’t get one with the same chip, the basic principle and the way the coding is done will still apply but you may need to do some more work to get your arduino to communicate with the sockets. You will only need one remote but you will require a plug socket for every electrical item or set of mains lights you wand to control independently – (i.e. I only ever use my TV with my Xbox so when ever I turn on the one I will require the other too. This means that I only need one RF plug socket for the two of them and a two way mains extension for them both the plug in to).
• Mains extensions
• Pattress block extenders (46mm depth recommended) – this is so the additional circuits will fit behind your standard light switch. One required for each set of light switches to be rewired. I bought mine at Maplin (http://www.maplin.co.uk/single-surface-pattresses-1286)
• 75mm electrical socket screws (2x pattress block extender)
• A router with at least one free Ethernet port that is also used for your WiFi network (you will also need to have access to the settings of this router)
• An iPhone or iPad (the app I’ve used and as such a fair proportion of the code is iPhone/iPad only. I’m sure there are android alternatives but you’d have to look around for them and change the code accordingly. I’ve tried to make the code as easy as possible to change the control method)
• Mains to USB power supply
• An ethernet cable
• A USB A to B cable
• Access to the mains breaker/fuse box in the building you’re installing this (if you don’t intend to do anything with the mains lights then you probably won’t need this)

Arduino libraries you will require:
• Adafruit’s modified RTC library (for interfacing with the clock module) – https://github.com/adafruit/RTClib
• RCSwitch library (this deals with the codes to be sent by the RF remote) – https://code.google.com/p/rc-switch/downloads/detail?name=RCswitch_2.51.zip&can=2&q=


Knowledge you will need:
• Soldering
• How to avoid electrocuting yourself when sticking your fingers into exposed light switches

Got all that? Let's get cracking!


Step 2: Opening the remote

 







Essentially the RF remote will still be used to control the sockets just that, rather than pushing the buttons like some sort of Neanderthal, it will be controlled by the arduino (which is in turn controlled by the touch screen on your iPhone).

To do this we will need to take apart the remote.

Firstly, remove the battery cover, which will reveal one of the six tabs that hold the front cover to the back of the remote. Using a flat blade or a small flat head screwdriver you can now pry this apart. I ended up loosening a couple down the side first as I found it to be easier but this might not be the case for everyone.

Roughly 25mm from the bottom of the remote and 35mm from the top there are tabs on either side. `Again, using your prying instrument of choice slide it down the small groove between the top and the bottom of the remote's casing and push these tabs until they come free. You may need to apply some levering pressure to get them to pop out properly.

Once you've done both the tabs on one side it should be much easier to release the tab in the battery compartment.

I found that loosening the tab at the top was now fairly simple (again push it with the blade or screwdriver until it pops free. I had to use a fair bit of levering pressure for this one.

Now you can just push the top of the casing against the bottom and the two tabs on the other side should pop free. If not, just repeat the initial process on the other side and you will have the top free (take a look at the photos which show where the tabs are if you're in any doubt.

You can now just pull out the circuit board. Huzzah!



Step 3: Connecting the remote to the arduino


 


We now need to solder three wires on to the exposed circuit board. One 5V, one ground, and one data control. The 5V and Ground go to the appropriate sides of the battery holder (the side with the larger spring is the ground side and the smaller side is the 5V side).

I was initially concerned about loosing range if I used 5V rather than the 12V the battery it was designed for but I haven’t found this to be an issue. If you do decide to use a separate power supply, make sure to connect the power supply's ground to the ground pin of the arduino else the data connection won’t work (they both need the same 0 reference)

The data wire must be connected to the Dout pin of the chip (see pictures). It doesn’t matter which pin on the arduino it goes into provided you change the code accordingly. I used pin 10 and as such that's what the code will have as a default.

Congratulations! The arduino is now connected.


Step 4: Setting up basic appliances ready for use


If you want to turn on things like TVs, speakers, lamps etc. then you can use the plugs you've already got!

Simply select which group and which channel you would like the device to have assigned to it on the back of the plug. You should note that there are a maximum of 16 possible separate plugs (four channels within four groups). You might want to consider limiting yourself to 12 as this will leave one full group free for your next door neighbour to use without them accidentally turning on and off your appliances and vice versa.

You will almost certainly want to keep a record of which appliance has been given what group and channel as you will need this later (I've got a big spreadsheet with all the information I need to program this stuff - more on that later).

To select the group and channel turn the upper and lower dials on the back of the plug (the upper dial is the group and the lower is the channel).

Plug the RF receiver into a wall socket and the appliance into the RF plug. Your appliance is now ready to be controlled by your arduino!

If you don't want to turn on the main lights in your house (or you don't fancy messing around with light switches and fairly high voltage electricity) then you can skip the next two steps.

Step 5: Taking apart the RF wall sockets

 








                                                 















We'll need to take apart the RF wall socket to get to the innards that will be used to control the main lights.

Firstly use a flat blade to prise off the ring around the prongs (there are some half exposed screw holes just underneath that make this very easy). The ring is connected at the two lower bulges and at the top. Use the blade to free it from the two lower bulges and then you should be able to pry it off with your hands.

Now the two screws are exposed (they're in the holes). The screws are a security Torx T15. I used a small flat head screwdriver that I didn't mind damaging to break off the security spike in the screw and then a standard Torx T15 screwdriver to remove the screws. I would highly recommend using the correct screwdriver though as it caused quite a lot of frustration!

Once you've undone the screws you should be able to open the bottom of the socket. The top is clipped by two small plastic tabs. Lifting the bottom should cause the top just to pop out. If you're really worried about damaging the enclosure you can use a blade to push the tabs in and release the top that way.

The part we're interested in the the part connected to the small circuit board. DO NOT touch the screw in the plastic covering at the top left of the board! This is part of the antennae and moving it, even slightly, can have massive effects on the range.

You will need to detach the three wires from the three terminals (may be a different number for different countries, I would assume the USA would only have two). The easiest way to get to the thick wires is to undo the small screw on the right hand terminal (a small flathead should do the job). You can then use a lat blade to lift the top half away from the bottom half.

Next cut the wires away from the terminals (it's best to try and keep as much wire as possible so cut as close to the terminals as possible). The released terminal is easy, the other two are fixed and a bit more fiddly.

You should now have the circuit board free from the enclosure.

On the back of the circuit board you will see the two five quadrant metal sections that are used to select which channel the board will respond to.

You will need to get or make two small jumpers. I just used a couple of very small bits of wire with stripped ends. These jumpers need to be soldered on to the board to permanently select what channel the board will respond to. This can be quite fiddly and I found that a board holder and helping hands/magnifier to be extremely useful here.

If you look at the back of the casing, the orientation of the numbers will be the same as the board flipped over (that is 1 and I on the far left, 2 and II at the top, 3 and III on the right, and 4 and IV on the bottom. The centre point needs to be connected to the appropriate surrounding point for the channel.

Congratulations! You how have the board setup to do your bidding!

Step 6: Re-wiring the light switches



                                                           


The very first thing you MUST do is turn of the breaker for the lights.

Most houses will have a separate breaker for the lights as apposed to the appliances. If this isn’t the case, either remove the fuse for the lights (often found in the cupboard under the stairs) or turn of the main breaker for the whole house. Under no circumstances should you fiddle with the light switches if the power to those particular wires is on!

Right, now back to the good part:

Use a medium sized flat head screwdriver to remove the screws on the light switch fitting. It should now come free from the wall. It may be a little bit stiff as mains power wires are quite thick and can be a bit reluctant to bend. Applying a bit of pressure when slowly pulling the switch away from the wall should get it all sorted.

Now you'll want to take a picture of the back of the switch now so you know which wires went where! If there are some wires the same colour, try and mark them so you know which is which. If your switch is a single switch this should be fairly strait forward.

Next remove the wires from the switch. There will almost certainly be small screws holding them in place and you will need to loosen these first.

Take the 46mm depth pattress and make enough holes in it for all the wires to go through easily (you should be able to push out the thin pieces of plastic that are use to cover the holes in the pattress). Pull all the wires through (including a/the wire connected to earth).

Once you have the switch part completely detached from any wires and the wall take out your multimeter and flick it to continuity testing mode. You will want to put the probes in the places that the wires were to check which ones connect when you flick the switch. If you have only a single switch then this will probably be unnecessary but some switches have an inverse ganging option too so you'll need to make sure you don't use that one.

Write down which connect to which when the switch is thrown.

Using that information and the picture you took earlier you should be able to work out which wires are connected when the switch is closed. These are the two wires that we are interested in for the moment.

Taking the circuit board we extracted we need to connect the two thicker wires to the two wires that we’ve just identified. Using the block connectors put one of the thick wires from the circuit board in one end and one of the two wires that we’ve just identified in the other and tighten it all up with a screwdriver. Do this again for the other one.

If you know which one of the wires from the light switch is always live then connect that to the one on the long side of the board.

Inside the hole the switch came from, there will probably be a connection between the wall and the yellow and green striped ground wire. The small wire on the circuit board needs to be connected to ground.

Once it’s all connected, flick the breaker back on and test it out. If it doesn’t work, turn off the breaker again and try swapping around the large wires from the circuit board. Test it again. If that doesn’t work make sure all is connected properly (particularly check the ground connection). If you can try checking with an unmodified remote to see if it is a range issue.

Step 7: Setting the IP addresses of the Arduino and iPhone






Firstly stack the Ethernet shield atop the arduino (if it’s an Arduino Uno it should just slot on, if it isn’t check out the www.arduino.cc website for advice).

Plug the Ethernet shield into the router. The next stage is to give the arduino and your permanent IP address iPhone or iPad (I will refer to the controlling device as an iPhone from here on in as that’s what I used). This means that they will be able to communicate with each other over your home network.

Find the IP address of your router (for mac users you can find it by going into the network settings within systems preferences, selecting airport, pressing advanced and going to the TCP/IP tab). Open up your internet browser of choice and type in this IP address. The web page that opens should be the setting page for your router. You will probably be asked for a username and password (the username is normally “admin” and if you haven’t changed the password “changeme” is usually a good bet – this information is on the back of many routers).

You will need to go into the advanced settings. It will probably ask you whether you are sure and warn you that you can royally stuff up your router if you start clicking things randomly. You will want to find the section that lists all currently connected devices and their IP addresses (for me it was in the "devices" menu).

Find your Ethernet shield (you can look for the mac address which will be printed on the bottom of your shield). Now you will need to reserve an IP address for this device. This is often just a tick box next to the device and this will mean that, whenever that device is connected to the network, it will be assigned the same IP address and that no other device can be assigned that address. Once you’ve done that, find your iPhone on the list of connected devices and do the same thing. Copy these down, as you will need to input them into the arduino code.




No comments:

Post a Comment

Join Us

//go.ad2up.com/afu.php?id=25365

© Copyright 2012, Design by Lord HTML.