Introduction: Home Automation With Arduino

In this Instructable I will attempt to explain how to create a home automation server that has the facility to allow common household electrical items to plug in to a common 5-way 240VAC/120VAC power strip. In my design I have included an 8-way relay board that uses 4 relays to switch 4 of the 5-way power strip outlets, with the remaining 4 relays available for hard-wiring more external devices. These relays will be able to be switched over the internet, or on a home network.

The items I have used for this are:

Arduino Nano - You can get cheap versions of these for around £3 - £4 from eBay.

8-way 5V Relay board (Relays rated at 250VAC 10A) - Around £4 from eBay.

5-Way power strip - £7 from eBay

Funduino W5100 Electronic Bricks Ethernet Network Module - £6 from

Perspex/plastic or whatever you can get to house it in.

Step 1: Connecting the Relay Board

Firstly we need to understand how to connect each device.

Lets start with the most simple of the peripherals - the 8-way relay board.

You can make your own relay board or buy one of the ready made ones. The ready made relay boards will be something like that shown in the picture. These relays are rated at 250VAC @10A or 30VDC @10A which will be enough for most applications (just don't go connecting your cooker or shower unit to them!).

They need a 5V supply and a ground connection from the Arduino. There are 8 more connections, each one will switch one of the 8 relays with a low signal (0V) or high (5V) signal. There is a shorting link (I haven't really tested this link, but I think it reverses how the relays are switched).

To connect this to the Arduino I soldered some 22 AWG gauge wire to the IN terminals and then soldered the other end of the wires to the Arduino digital pins such that:-

IN1 - Arduino Pin 2

IN2 - Arduino Pin 3

IN3 - Arduino Pin 4

IN4 - Arduino Pin 5

IN5 - Arduino Pin 6

IN6 - Arduino Pin 7

IN7 - Arduino Pin 8

IN8 - Arduino Pin 9

(I left Pins 0 and 1 as they are used for Serial communication and debugging)

Step 2: Connecting the Ethernet Module

The next peripheral is the Funduino W5100 Ethernet Network module. This uses the Ethernet.h library for Arduino which comes with the Arduino IDE. The device communicates using SPI, which means it needs 4 connections, MOSI, MISO, SCK, and SS. If you look at the Arduino schematic you can see that these connections are through Arduino Pins 10, 11, 12 and 13. So you match up these pins with the W5100 pins. The W5100 module also needs 5V and GND connections so cables are soldered to these connections.

At this point I should mention that I have mounted the Arduino Nano on a piece of veroboard so that it is easier to break out the connections.

Step 3: Modifying the 5-Way Power Strip

So, now that the relay board and Ethernet module are connected to the Arduino Nano we can discuss the 5-way power strip.

Notice that I have only modified 4 of the 5 sockets in the power strip... This is deliberate. The 5th socket is used as a permanent supply for the Arduino via a micro-USB charger adapter (these are relatively easy and cheap to source and in fact any USB phone charger or similar will do).

There are ways to power the Arduino without using a USB charger, but I found this to be the simplest way at the time with the components I had available.

Using an adaptor to gain more socket outlets from the one un-modified socket would enable you to use a powerline ethernet adaptor that transmits your ethernet connection around the home using the mains wiring.

When I opened up the 5-way socket I noticed that the Neutral line was connected using a solid brass (maybe copper) bus-bar track, which was also fed through the switches of the power strip. To modify this I used a heavy duty pair of snips to remove a small section of the track, therefore creating a break. I then soldered some size 16 AWG cable to each side of the modified track which are the wires you can see that break out of the power strip and go to the 4 relays. This means that the relays control the supply to each of the 4 sockets (and neon lamps).

Please ensure that you know the dangers of modifying mains electricity and that even your Home Insurance could be made in-valid from following this Instructable.

Step 4: Housing the Hardware

As you can see from the photos, I have mounted all of the hardware between two sheets of 5mm perspex. This is to prevent inadvertent contact with any high voltages. The four remaining relays are available for switching extra devices (garage door openers, room lighting, security lights etc). Please ensure that you understand the current capability of these relays (10A at 250VAC or 30VDC) and you utilize them accordingly.

Step 5: Writing the Software

I'm not much of a software guru, thankfully others have worked tirelessly to provide great services to us tinkerers!

To allow me to control this project from my mobile phone there is a great service called Blynk.

This app can be downloaded for both IOS and Android.

It also allows me to control each relay and gives feedback to show the current state of each relay (important if you want to switch stuff when you are somewhere else, so that you are confident that whatever you have switched via the app has actually been physically switched).

I will not go into the steps required to add the Blynk libraries, this can be found over at the Blynk website, but my code to control, and to receive feedback is as shown below:-

#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <SPI.h> #include <Ethernet.h> #include <BlynkSimpleEthernet.h> #include <SimpleTimer.h> #define RELAY1 2 #define RELAY2 3 #define RELAY3 4 #define RELAY4 5 #define RELAY5 6 #define RELAY6 7 #define RELAY7 8 #define RELAY8 9 char auth[] = "Your Auth Token"; WidgetLED led1(V1); // set up LED widgets WidgetLED led2(V2); WidgetLED led3(V3); WidgetLED led4(V4); WidgetLED led5(V5); WidgetLED led6(V6); WidgetLED led7(V7); WidgetLED led8(V8); byte relay1State; byte relay2State; byte relay3State; byte relay4State; byte relay5State; byte relay6State; byte relay7State; byte relay8State; SimpleTimer timer;

void setup() { Serial.begin(9600); Blynk.begin(auth); timer.setInterval(1000L, setVirtualLeds); // every 1 second check relays and set } // virtual LEDs to indicate on or off.

void setVirtualLeds() { relay1State = digitalRead(RELAY1); relay2State = digitalRead(RELAY2); relay3State = digitalRead(RELAY3); relay4State = digitalRead(RELAY4); relay5State = digitalRead(RELAY5); relay6State = digitalRead(RELAY6); relay7State = digitalRead(RELAY7); relay8State = digitalRead(RELAY8); if (relay1State == LOW) { led1.on(); }else{;} if (relay2State == LOW) { led2.on(); }else{;} if (relay3State == LOW) { led3.on(); }else{;} if (relay4State == LOW) { led4.on(); }else{;} if (relay5State == LOW) { led5.on(); }else{;} if (relay6State == LOW) { led6.on(); }else{;} if (relay7State == LOW) { led7.on(); }else{;} if (relay8State == LOW) { led8.on(); }else{;} }

void loop() {;; }

Hopefully you can replicate this project easily by following this Instructable, have fun!