A few weeks back we published a tutorial “Home Automation using Raspberry Pi” in rootsaid.com which was well received among hobbyists and college students. Then one of our members came up with an Arduino Home Automation system using NodeMCU.

Home Automation

Arduino Home Automation System

Here we will be showing you how to build an Arduino Home Automation System that can control electrical devices like lights, fans, garage doors etc using our mobile phone from anywhere around the world. To build this DIY Home Automation System, All you need is an Arduino Board, some relays and an android phone.

Before starting our Arduino Home Automation Tutorial, I would like every one reading this post to get a clear idea about ‘Home Automation’ and ‘Arduino’. So I will write a little bit about them before starting the tutorial.

If you are an expert in this field you can skip this and straight away go to the DIY Home Automation Tutorial.

Sponsor Link

This Project is Sponsored by UTSource. UTSource is a professional electronic components supplier.

What is Home Automation?

Home Automation is a convenient way to control and monitor different day to day devices and appliance that we use at home. These include held lighting, air conditioning, garage doors, security cameras, motion sensors, energy control units and whether sensors as well. Home automation solutions largely vary depending up on the functionality and scope.

DIY Home Automation

Most modern systems feature a central controlled panel also known as the head. The Head of the home automation system connects to the home WiFi network and becomes a primary interface through which all of your home utilities to be controlled remotely.

This type of system is expandable, which means you can add more devices to this ecosystem in the future as your requirements expand. Many home automation system providers develop applications for all popular platforms that allow the system to answer remotely and control their home utilities using their smartphones and tabs. You can simply install their apps in you mobile, tab or PCs, add new device, configure them and start using it remotely.

How Home Automation Works?

Home Automation Devices

You can add and connect all appliances ranging from thermostats, security cameras, lights to weather meters,motion sensors and energy control units. This means there is no separate remote controls for different devices and you dont have to manually controlling each device.

Advantages of DIY Home Automation System

You can control all your home devices using your internet enabled smartphone from anywhere in the world.You can set actions such as scheduling like make the blind to close if strong winds or detected by wind sensors. As a result modern installation of home automation systems means you can have wireless control all over your home just by using your smartphone, whether you were in the home or away. You can switch On or OFF group of lights by a single touch.

Apart from such convenience and control it is possible to monitor all your home security cameras while in the office or away from home. So you were always in control of you home no matter where you are.

You can build a wireless home automation system that fits your needs and keep you notified about what is happening in and around your home when you are at work or enjoying a holiday. You can monitor your home temperature using your smart phone and make adjustments even if you are away from home. This means when you’re returning home from a hard day, your room temperature will be perfectly adjusted to your comfort.

Why Home Automation?

With home automation, you can carry out all day to day tasks using your smartphone. You can get complete remote home control from your smartphone as well as allowing you to switch on an individual lights when you are away from home. Home automation allows you to activate a group of devices with a single touch; this not only gives you peace of mind but also helps keep your utility bills and monitor home security.

The hub connected to your magnetic door sensors, home surveillance cameras, smoke sensors and motion sensors can be easily configured to sent to push alerts to your smartphone and when you are away and any anomaly is detected.

Home automation also makes it possible to open and close all of your windows or blinds shouting from anywhere in your home as well as allowing you to control them using your smartphone. You can send a program to lower blinds by sensing the environment and automatically lower the blinds during extreme sunlight there by keeping your house cool during the summer and saving energy and utility costs.

Parts of Arduino Home Automation System

MicroController – The Brain

Microcontroller

Have you ever heard of the word microcontroller and wondering what it is?

A micro controller is a circuit board that has a chip on it that can be programmed to do many different things. You can read information from sensors using a micro controller. For instance if you want to know how bright it is in a room you can use a photo resist which is sensitive to light or you could detect when someone walks into a room with a motion sensory. Even a GPS receiver can tell you where on the globe it is.

That’s just a small sample of the different kinds of input that sensors provide but what can you do with that data is what makes it a micro controller. Using the output of the sensors, you can process, control devices, display and store data. You can do various projects in electronics – hobby projects, robotics as well as home automation using this tiny chip by simply uploading the code without the need of altering the circuit.

Arduino

Arduino Uno

So you may have heard about a thing called Arduino and you’re wondering what is this called Arduino? At its essence the Arduino is an electronics tool for making really cool things and people make all types of really awesome things like atomic clock, quad copters, pet feeders, art projects, 3D printers and even electron microscopes and the list goes and it’s going to keep going on for a long time to come.

Micro controllers are really just a tiny computer that does some type of computation. Now traditionally created circuits have been a little difficult figure out how to use. You should we have to have some electronics knowledge or be able to know how to program in order to get them up and running.

But with the Arduino team has done is make using a specific integrated circuits so easy to use that anybody without any prior electronics programming knowledge, really get started relatively simply.



The way they’ve done is they made the hardware easily accessible. So the Arduino is just a printed circuit board and on that printing circuit board is the Micro Controller that we use and on the outside they have pin headers which allow you to connect different sensors to the Micro Controller. Moreover, they have set it up so that you can easily connect it to your computer with a USB cable.

Now on the software side they’ve created an entire software programming environment that is very streamlined for somebody who’s just getting started with programming to make it easier than ever to program.

Arduino MKR1000

Arduino MKR 1000

Today I have an Arduino MKR1000 which is an Arduino board with built-in WiFi chipset specially designed for wireless connectivity for IOT projects such as Home Automation using Arduino as well as Robotics.

What can we do with an Arduino?

In Arduino, I already mentioned a couple things that people have made with their Arduino. So what can you really do with an Arduino?

Well you can perform logical computations. Let me give you an example of some a logical computations that are a little more down to earth. so an example would be when I press this, that happens or when the light comes on that goes off. When this opens, I get a tweet. If the soil is dry, add some water. While the sun is shiny, keep the air conditioner ON.

You could even see something more complicated like when I press this, if the sun is shining and the light is touching a point, then add some water to the soil, send me a tweet and turn ON AC.

The Relay – The Switching Element of DIY Home Automation System

Relays are simply switches that are close and terminate electrical connections mechanically. That means it can control an electrical device in a circuit by closing and breaking connections in that circuit.

Relay

Internal Relay Structure

Look at the image above. There are five terminals in a normal relay. Two of the terminals are end points of a coil which will be used for energizing the coil, one is the Common terminal, a Normally Closed terminal which will be shoted to the Common terminal when the coil is not energized and a Normally Open terminal which will be in contact with the Common terminal when the coil is energized.

This is how the relay works. In our case, we will be connecting

GPIO pins to One End of Coil

Ground to other End of Coil

Phase of Main Power Supply to The Common terminal or Pole

One Terminal of bulb (Or other electrical Appliance) to Normally Open Terminal

And the Other Terminal of Bulb to Neutral Point of Main Power Supply

Depending upon the output of arduino board, you can select your relay. Since the Output of Arduino MKR1000 GPIO pins are 3.3V, you will have to buy a 3.3V Relay. You can purchase the relay board of 4 relays that is compatible with Raspberry Pi from here or click on the image.

DIY Home Automation Using Arduino

Our world is running fast. We can see automation all around us; from industries to home. Of course they play a major part in our busy life. Home automation mainly focusses on automating and controlling various electrical devices such as lights, fans, garage doors, sensors from within the home or remote location via a smart phone or a tab or even voice controlled.

Here we will teach you hoe to setup a cheap but effective DIY Home Automation Using Arduino. Using this Simple Home Automation System using Arduino, you can turn ON and OFF various electronic/electrical devices using your mobile phone, tablet or a computer in your home from any where around the world.

In this, the board is configured in such a way that, whenever I power it up, it will connect to my home WiFi network and starts a web server at port 80, which can be accessed from any web browser in my phone, tab or computer. This board is connected to relay board which is then connected to different electrical devices. Now let us start to build our Home Automation Using Arduino.

Components Required

Click on them to purchase from amazon

Arduino MKR1000

Relay

An Android Phone or tab

A WiFi network

Steps

Step 1 : Download, Install and Setup Arduino IDE

First thing for us to do is to download and set up Arduino IDE from Here.

Once your download is complete, extract the file and install the software. After installation, open up arduino IDE, go to Board Manager and add Arduino MKR1000.

Once it is complete, now its time to add Arduino MKR1000 board to the board manager. Then you have to go to library manager and install WiFi101 library from the library manager.

Step 2 : Connections

Unlike most Arduino boards such as Arduino UNO or nano, this board (MKR1000) runs at 3.3V. The maximum voltage the GPIO pins can withstand is 3.3V. If you apply a voltage greater than 3.3V will damage the internal circuit. So if you are planning on using sensors that use 5V, proper level shifting circuits should be employed.

That is the main reason why we are using a 3.3V relay; we can connect GPIO pins directly to the Relay.

In this board we will be using 4 Digital Pins to control 4 devices – D0, D1, D2 and D3

D0 - First Relay in D1 - Second Relay in D2 - Third Relay in D3 - Fourth Relay in

And in the relays we connect our devices. If you dont know how, read the above part in which I explained everything about the working of the relay.

Step 3 – The Code

Now all you have to do is download arduino code from the below link and start a Web Server on Arduino MKR1000. Download the sketch from the link below. Download

DIY Home Automation Code Explained

Here I will various parts of the code

char ssid[] = "www.rootsaid.com";//Your WiFi Name char pass[] = "RootSaid";//Your WiFi Password

Here you enter your WiFi ESSID as well as your Password. Once the code is uploaded, the board will try to connect to the WiFi network with this ESSID and Passphrase if it is available.

pinMode(0, OUTPUT); pinMode(1, OUTPUT); pinMode(2, OUTPUT); pinMode(3, OUTPUT);

The 4 pins we will connecting to the relay input.

while ( status != WL_CONNECTED) { digitalWrite(ledpin, LOW); Serial.print("Attempting to connect to Network named: "); Serial.println(ssid); digitalWrite(ledpin, HIGH); status = WiFi.begin(ssid, pass); delay(10000); }

This will try to connect to the WiFi network using the credentials provided earlier.

server.begin(); printWifiStatus(); digitalWrite(ledpin, HIGH);

This will start a server in port 80 and serves the webpage

if (currentLine.length() == 0) { client.println("HTTP/1.1 200 OK"); client.println("Content-type:text/html"); client.println(); client.print("www.rootsaid.com<br>"); client.print("https://www.youtube.com/c/rootsaid<br>"); client.print("<br>"); client.print("<h1>Home Automation using Arduino<br>"); client.print("<br>"); client.print("<h1>Click <a href="/device1on">here</a> Turn Device 1 ON<br>"); client.print("Click <a href="/device1off">here</a> Turn Device 1 OFF<br>"); client.print("Click <a href="/device2on">here</a> Turn Device 2 ON<br>"); client.print("Click <a href="/device2off">here</a> Turn Device 2 OFF<br>"); client.print("Click <a href="/device3on">here</a> Turn Device 3 ON<br>"); client.print("Click <a href="/device3off">here</a> Turn Device 3 OFF<br>"); client.print("Click <a href="/device4on">here</a> Turn Device 4 ON<br>"); client.print("Click <a href="/device4off">here</a> Turn Device 4 OFF<br></h1>"); client.println(); break;

Displays the webpage.

if(currentLine.endsWith("GET /device1on")) { digitalWrite(0, HIGH); } else if(currentLine.endsWith("GET /device1off")) { digitalWrite(0, LOW); } else if(currentLine.endsWith("GET /device2on")) { digitalWrite(1, HIGH); } else if(currentLine.endsWith("GET /device2off")) { digitalWrite(1, LOW); } else if(currentLine.endsWith("GET /device3on")) { digitalWrite(2, HIGH); } else if(currentLine.endsWith("GET /device3off")) { digitalWrite(2, LOW); } else if(currentLine.endsWith("GET /device4on")) { digitalWrite(3, HIGH); } else if(currentLine.endsWith("GET /device4off")) { digitalWrite(3, LOW); } else { Serial.println("Invalid"); }

This will turns the GPIO pin output to HIGH or LOW depending upon the links pressed. Download the code, paste it on the IDE and upload the code to your arduino MKR1000.

Testing

Home Automation System using Arduino is now ready. Once the code is uploaded, fire up the serial monitor and you will see the IP Address of the device.

Take out your phone, start your favourite web browser and enter the IP Address of your Home Automation System.

If everything goes right, you will see the page that is hosted by arduino. You can control all the device from there.

Feel free to edit the code. If you are stuck somewhere, you can use the forum. We will get back to you.

Rate the Project

Did you find this page useful? Help us to improve by rating this page.

Name Email Review Title Rating Review Content