Third party cookies may be stored when visiting this site. Please see the cookie information.

Electronic project - Simple home automation with an Arduino

Switching mains electricity with an Arduino and a remote control

Home electronics can open up a new dimension in home automation especially when used with an Arduino or Raspberry Pi. There is however a very real danger when using mains electricity, including risk of electricution and danger of electrical fires if the components are not rated correctly. See this guide on risks when working with electricity. This design greatly reduces any risk by avoiding the mains electricity by using commercially available remote control plugs or light fittings. In particular the plugs (shown below) do not need any work to be done on the house electrical system, the light fittings do and need to be installed by a competent adult or qualified electrician.

The project is based on the Arduino as an programmable controller which can be used on it's own or connected to a computer such as the Raspberry Pi. I have also provided the instructions for home automation using a Raspberry Pi and PiFace digital without needing the Arduino.

Remote control sockets

This circuit uses a remote control socket or other home automation remote control devices. The sockets are available as a plug adapter that goes between the normal wall socket and the plug for the device to control. They are available as standard on/off switches or with a dimmer for controlling a light. Either will work for this circuit, but a dimmer socket can only be used for lights and even then only certain light bulbs that are "dimmable".

Remote control electrical socket for mains plug

Please note that there is no in-built security or protection from neighbours with similar controls. There are usually multiple channels (in the devices I used 4), but there is a risk that others may select the same channel. As such these should not be used for anything that could pose a risk if turned on or off without notice. For example do not use for a critical light (eg. staircase or cellar) where it may be dangerous if the light turned off unexpectedly. Check the instructions with the particular home automation device for more details.

I have used these for Christmas fairy lights and other decorative lighting, and as an additional entry light, but there is far more potential particularly when using the Raspberry Pi.

The down-side of this project is that it will invalidate your warranty for the remote control and the soldering can be quite difficult (depending upon the type of remote control), although the cost of an additional remote control is usually quite reasonable, or even the cost of buying a set of sockets is still the fraction of the cost of a full home automation system.

Buying home automation remote control sockets

I used a Byron remote control socket set available from B&Q. These were originally bought to make it easier to turn Christmas fairy lights on without crawling under the Christmas tree. There are other makes available from various suppliers including DIY stores or electrical retailers. Typically plug-in sockets cost about £15 to £25 for between one and three sockets (perhaps a little more if it includes a dimmer socket), but you may need to buy an additional set or remote control if you want to use these as they were intended as well as it will not be possible to use the control normally after making the changes. You need a device with a basic on/off remote control and not a timer or other advanced remote control (although you can still continue to use them alongside this project). The one shown on the right appears to be a newer version of the remote control that I bought some time ago - I don't know if this will be any easier or harder to solder to (see later). The remote control shown later is a similar button design, but benefits from an additional master on and off buttons that can control all three devices simultaneously.

Remove the remote control circuit board

Rather than having to create a wireless circuit to match the specification of the remote control the easiest way is to modify the existing remote control so that it can be controlled by an external circuit (typically actuated by an Arduino or Raspberry Pi). Each of the buttons on the remote are push to close switches, so we can connect a relay across each of the switches to emulate a user pressing each button. Before taking the remote control apart make sure it works normally first. It's very frustrating to spend time trying to diagnose your circuit if it's connected to another circuit that didn't work in the first place.

Remote control for electrical socket, in pieces

The remote control is unscrewed to access the internal circuit board. On these remote controls the remote can be one of 4 different settings which is chosen by a switch on the back. In this case I have set it to switch "C" (most users will leave at the default "A" position which is best avoided), so I've soldered a wire in the 3rd position shown in red on the top image. Then on the front side a wire needs to be soldered on to each side of each switch you want to control. In this particular case there is a matrix configuration for the switches so several of the switches share the same connection, reducing the number of wires required (see the colouring on the diagram below).

Remote control socket - inside the remote control

Soldering wires to the remote control circuit

For this particular remote control then the soldering was the hardest part. I'd recommend this for those with some experience of soldering. Other remote controls may be easier to solder to.

For the switch on the rear I was able to solder wires direct to the switch contacts. For the other switches I tried scraping away some of the coating on the circuit board, but was unable to get the solder to stick to the track. I therefore soldered the wires to the holes where the tracks go from one side of the double sided circuit board to the other. Failing that it may have been possible to solder to the pin of the integrated circuit on the board, but I would only do that as a last resort as it is a SMD device and so there isn't much lead to solder to.

I used devices one and three, but that is only because that is what I'd already set my corresponding devices to; I used device two for another circuit that I didn't want controlled by the Raspberry Pi. Note that when I refer a device this can actually be multiple sockets / devices, but are all programmed to respond to the same signal.

This remote control normally uses a 3V button cell battery, but it was not possible to hold it in place without the case, so additional wires were soldered on to those to supply 3V from two AA batteries in a battery holder. The photo below shows the remote control circuit board complete with wires soldered onto it.

Remote control socket - inside the remote control with wires soldered in place

Pressing the remote control switch

To emulate a user pressing the switch I am using a relay. A relay is a switch that changes position when current is applied through a magnetic coil. Essentially you apply a voltage to one pair of contacts and it causes a switch across the other two contacts to close. There is no electrical connection between the input signal and the output so there is no risk of anything from the remote control damaging the Arduino. As the current in the remote control is so small then a reed relay is sufficient. These are similar to standard relays, but use less power to switch them on.

The benefit of using an Arduino over the Raspberry Pi is that it is able to supply much more power through it's outputs. The Arduino provides 5v so can drive a standard 5v reed relay directly.

Reed relay circuit

The reed relay that I used is the HE751A0510. This is a 5v reed relay that uses about 10mA. It can therefore be powered directly from the 5v output.

The circuit diagram below shows how each reed relay connects to the Arduino.

Home automation - circuit diagram Arduino to remote control

I used four relays, which is sufficient for two devices with an on and off for each. These connect to four different outputs from the Arduino. These can use the outputs from any of the digital ports from 2 upwards. Digital ports 0 and 1 are used for serial communications with the Arduino and we don't want the relays triggering when communicating with it. Therefore ports 0 and 1 should be avoided (or for the relays to be disconnected when uploading new sketches). In this example I've used the following outputs:
Pin 2 - device 1 on
Pin 3 - device 1 off
Pin 4 - device 3 on
Pin 5 - device 3 off

Note that there is a diode shown in the circuit diagram connected in the reverse direction across the relay coil. This is required due to the back EMF produced when the magnetic coil is de-energised. The particular model of reed relay used has the diode included within the package. The last two digits denote the features of this relay which in this case indicates that it "includes Coil Suppression Diode". If using a different reed relay then an external diode needs to be connected. Normally a schottky diode should be used as a suppression diode, although with a reed relay any normal diode would be sufficient.

Sample sketch code

This sample code shows how the mains powered equipment can be switched using the Arduino. This example just shows parts of the code that you will need to add to your own sketches.







// setup pins

int device1_on = 2;

int device1_off = 3;





// Include in setup()

pinMode(device1_on, OUTPUT);

pinMode(device1_off, OUTPUT);



// function to switch on / off

void mains_switch(int port) {

  digitalWrite(port, HIGH);   // turn the relay on

  delay(500);                 // wait for 0.5 second

  digitalWrite(port, LOW);     // turn the relay off

}



Practical use

The code above illustrates how to turn devices on and off, but isn't particularly useful on it's own. So what about some practical uses:

  • A light that comes on and off at intervals during the evening to make it appear someones at home *
  • A welcome home light that comes on just before you are due to arrive home, but only during the winter months *
  • A light that turns itself off, but only after a light has been switched on in a different room
  • A voice activated switch - eg. speaking "Lights on"
  • Motion activated lights (with motion sensors)
  • Washing maching / appliance timer
  • Internet enable switch through a web page
  • Fish pond / fish tank pump activated based on sampling of the water quality
  • Heat lamp for a pet

These are just a few examples, but there are lots of other ways this can add home automation to mains powered devices. Please keep in mind the safety implications mentioned earlier and also that if a heater / radiator is used that it is positioned so that it does not pose a fire risk.

Some of these can be done using sensors connected directly to the Arduino, but for others you may need to use a computer or the Arduino Tre. Note that the Arduino Due should not be used with the 5v reed relays without using a buffer as the Due is designed for 3.3v outputs.

Summary

This has provided the details of how to control power to mains electrical devices without making any physical connections to the mains electricity components. There are still some safety factors that need to be considered, but it's much safer than say installing your own reed switch into an existing mains circuit.

This still needs some programming and optionally additional hardware to give it a more practical use, but it has provided sufficient to get a practical circuit up and running. I'd be interested in hearing what other people make towards home automation.

Previous Home automation - RasPi
Home automation - RasPi
Next Environment Monitor - Temperature & Humidity
Environment Monitor - Temperature & Humidity