Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
51 views

Home Automation Using Arduino and ESP8266

This document summarizes a student project on home automation using an Arduino Uno microcontroller, ESP8266 Wi-Fi module, and IR sensors. The system aims to automate home appliances and allow remote control. The Arduino processes sensor data and controls appliances. The ESP8266 enables Wi-Fi connectivity and a web interface. IR sensors detect motion and count people entering/exiting to automate appliances. The system turns appliances on when motion is detected, allows control via IR remote or web app, and turns everything off when the room is empty.

Uploaded by

sarkochile
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

Home Automation Using Arduino and ESP8266

This document summarizes a student project on home automation using an Arduino Uno microcontroller, ESP8266 Wi-Fi module, and IR sensors. The system aims to automate home appliances and allow remote control. The Arduino processes sensor data and controls appliances. The ESP8266 enables Wi-Fi connectivity and a web interface. IR sensors detect motion and count people entering/exiting to automate appliances. The system turns appliances on when motion is detected, allows control via IR remote or web app, and turns everything off when the room is empty.

Uploaded by

sarkochile
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

International Journal of Advanced Engineering, Management and Science (IJAEMS) [Vol-2, Issue-9, Sept- 2016]

Infogain Publication (Infogainpublication.com) ISSN: 2454-1311

Home Automation Using Arduino and ESP8266


Samir Samanta, Koushik Kr. Khan, Arghya Bhattacharyya, Sounak Das, Atul Barman, Mr.
Koushick Mathur

University Institute of Technology, The University of Burdwan, Golapbag (North), Burdwan, West Bengal, India

Abstract— With the advent of technology, life has become In addition to these there are many more possibilities that
faster in pace and shorter in interactions, with others, as we can explore with Home Automation systems.
well as with the surroundings. In such a scenario, there is a We are using [2]Arduino Uno development board as the
need to have an endeavor to have everything at the push of brain or the microcontroller unit of the system, [3]ESP8266
a button away, and more importantly, automated. Home as the World Wide Web interface and IR sensors to count
Automation is such an endeavor, in which, all the electrical the number of people entering or leaving the room.
appliances present at home are connected to each other, 1.1Arduino Uno
having interactions with sensors placed at strategic According to the description given in the Arduino Website,
positions in a closed loop manner in order to perform “Arduino/Genuino Uno is a microcontroller board based on
meager tasks automatically, leaving less burden on the the ATmega328P. It has 14 digital input/output pins (of
humans. With this project we are promoting the fact that which 6 can be used as PWM outputs), 6 analog inputs, a 16
Home Automation can greatly contribute to energy MHz quartz crystal, a USB connection, a power jack, an
conservation too. ICSP header and a reset button.”
Keywords— Home Automation, ESP8266, sensors.

I. INTRODUCTION
A brief definition of Home Automation may be given in this
way as, “Home Automation is the technology, in which
every electrical appliance present inside a particular house
are connected to one another and to a set of “sensors”
placed at particular strategic positions, reading specific data
in a closed loop fashion to serve the purpose to automate all
the connected home appliances.”
The most important part in a fully automated system are the Fig.1.1: Arduino Uno Development Board
sensors, be it [1]IR motion sensors, heat sensors, smoke
detectors. The data they acquire are then sent to the Arduino is an open source project aiming at developing
microcontroller unit, which then processes the data and greater curiosity towards DIY projects among students and
performs specific switching of the Home Appliances in a enthusiasts. Along with the development board, comes the
real time fashion. Arduino IDE based on a programming language called
In this project we have set these specific objectives for our Processing for programming the microcontroller.
version of the automated system.
1. Turn ON all the appliances when a 1.2 ESP8266 Wi-Fi Module
person enters the room. The ESP8266 is a low-cost Wi-Fi chip with full TCP/IP
2. He/They can then turn them ON or OFF stack and microcontroller capability produced by Espressif.
using an IR remote, or use a web This small module allows microcontrollers to connect to a
application for the purpose as Wi-Fi network and make simple TCP/IP connections
convenient. using AT commands.
3. Turn off everything whenever everyone The very low price and the fact that there were very little
leaves the room, in other words, when external components on the module which suggests that it
there are no one inside. could eventually be very inexpensive in volume make it the
4. A person can remotely access the home component of choice for our needs.
appliances if he feels the need be.

www.ijaems.com Page | 1446


International Journal of Advanced Engineering, Management and Science (IJAEMS) [Vol-2, Issue-9, Sept- 2016]
Infogain Publication (Infogainpublication.com) ISSN: 2454-1311
1.2.1 AT (Hayes) Commands
The Hayes command set is a specific command
language originally developed by Dennis Hayes for
the Hayes Smartmodem 300 baud modem in 1981. The
command set consists of a series of short text strings which
can be combined to produce commands for operations such
Fig.1.2: Pin diagram of ESP8266
as dialing, hanging up, and changing the parameters of the
connection. The vast majority of dial-up modems use the
Hayes command set in numerous variations.

[4]
Some AT Commands used in our project with the ESP8266 and there functions
AT Command Response Description
AT OK
Description about the device To reset the module and refresh all
AT+RST
followed bt “OK” the settings.
Description about the device
AT+GMR
followed by “OK”
1. The module acts as a Wi-Fi
enabled device that must
AT+CWMODE=<1,2,3> OK be connected to a router.
2. Acts as a Wi-Fi Hotspot
3. Acts as both
Information about every Wi-
To get to know if any AP is present
Fi router present in the
AT+CWLAP so that to connect to it.
vicinity separated by
Note: Doesn’t work in Mode 1.
newlines.
WIFI CONNECTED To connect to a specific access
AT+CWJAP=<SSID>,<password> WIFI GOT IP point.
OK Note: Doesn’t work in Mode 1.
To set the Baud rate of the module
in accordance of the baud rate of the
AT+CIOBAUD=<baud rate> OK
microcontroller with which it is
used.
To use the module in multiplexed
AT+CIPMUX=1 OK
mode.
To get the message from port
AT+CIPSERVER=1,80 OK
number 80.

1.3 IR Sensors coded pulses from the IR transmitter. A signal is generated


We are using TSOP1738 IR sensor. The TSOP 1738 is a when PIN photodiode receives the signals. This input signal
member of IR remote control receiver series. This IR sensor is received by an automatic gain control (AGC). For a range
module consists of a PIN diode and a pre amplifier which of inputs, the output is fed back to AGC in order to adjust
are embedded into a single package. The output of TSOP is the gain to a suitable level. The signal from AGC is passed
active low and it gives +5V in off state. to a band pass filter to filter undesired frequencies. After
When IR waves, from a source, with a centre frequency of this, the signal goes to a demodulator and this demodulated
38 kHz incident on it, its output goes low. TSOP output drives an NPN transistor. The collector output of the
module has an inbuilt control circuit for amplifying the transistor is obtained at Pin 3 of TSOP module.

www.ijaems.com Page | 1447


International Journal of Advanced Engineering, Management and Science (IJAEMS) [Vol-2, Issue-9, Sept- 2016]
Infogain Publication (Infogainpublication.com) ISSN: 2454-1311

Fig.1.3: TSOP1738 Pin Diagram

II. SCHEMATICS AND CODES


2.1The IR Sensor Circuit
To make use of the IR sensors, we have placed two IR LEDs at each side of the door, i.e., one is kept on the inner side and the
other on the outer side. Along with them the two TSOPs are placed opposite to them for detection of presence.

Fig.2.1: The Sensors Positioned At The Door

2.1.1Transmitter Part

Fig.2.2: 38kHz IR Transmitter

www.ijaems.com Page | 1448


International Journal of Advanced Engineering, Management and Science (IJAEMS) [Vol-2, Issue-9, Sept- 2016]
Infogain Publication (Infogainpublication.com) ISSN: 2454-1311
We have used a 555 astable multivibrator to produce near To drive high voltage electrical appliances, we have used
about 38kHz output and used it drive two IR LEDs as 12V relays.
shown in the above figure. These LEDs would then go 2.4 Calculating the Number Of Persons Inside The
about to be used as the 38kHz IR sources for the two Room
TSOPs to work with. Let us assume two variables IN and OUT for the respective
2.2.2 Reciever Part sensors. IN is providing a fictional value 0 when no one is
The TSOPs need a power source of about 5V which can be obstructing its source an1 otherwise and same for out. Then
provided by the in built power source present in the UNO if OUT=1 given that IN was already 1 then its understood
board. The outputs of the TSOPs are analog values, which that the person is going outside and thus a counter is
are then connected to two of the six analog inputs present in decremented accordingly. And vice versa is applicable for a
the Arduino Board. person entering the premises.
Following is the Arduino Code used in our project.
int c=0;
int inner=0;
int outer=0;
int A=0,B=0;
int fa=0,fb=0;
void setup() {
pinMode(4,OUTPUT);
Fig.2.3: TSOP1738 Connected To Arduino Uno pinMode(5,OUTPUT);
The analog input to the Arduino is decoded into an integer pinMode(6,OUTPUT);
value between 0-1024. Based on that we can judge if a Serial.begin(9600);
particular set of sensors has been triggered or not. }
2.2 ESP8266 Interfacing To Arduino void loop() {
Connecting an ESP8266 Wi-Fi module to the Arduino is inner=analogRead(A4);
quite simple. We just need to connect the Tx of ESP to the outer=analogRead(A5);
Rx of Arduino and vice-versa. There are hardware serial if(inner<500)
ports in Arduino, marked Tx and Rx but we have used the {
softwareserial header file to make 2 and 3 as Tx and Rx for B=0;
our purposes. }
else
{
B=1;
}
if(outer<500)
{
A=0;
}
else
{
A=1;

}
if(A==0)
Fig.2.4: ESP Connected To Arduino Uno {
The ESP takes about 300mA current. So, we had to use a fa=1;
generic Breadboard Power supply, which has a 12V input if(fb==1){c--;}
and can provide 12V,5V and 1.3V needed for the ESP8266. }
2.3 Driving Electrical Appliances else
{

www.ijaems.com Page | 1449


International Journal of Advanced Engineering, Management and Science (IJAEMS) [Vol-2, Issue-9, Sept- 2016]
Infogain Publication (Infogainpublication.com) ISSN: 2454-1311
fa=0; senddat("AT+CIPMUX=1\r\n",1000,DEBUG); //
} configure for multiple connections
if(B==0) senddat("AT+CIPSERVER=1,80\r\n",1000,DEBUG); //
{ turn on server on port 80
fb=1; }
if(fa==1){c++;} void loop()
} {
else if(esp8266.available()) // check if the esp is sending a
{fb=0; message
} {
Serial.println(inner);
Serial.println("\n"); if(esp8266.find("+IPD,"))
Serial.println(outer); {
Serial.println("\n\n"); delay(1000); // wait for the serial buffer to fill up (read
delay(500); all the serial data)
// get the connection id so that we can then disconnect
} int connectionId = esp8266.read()-48; // subtract 48
2.5 Controlling Arduino Pins Using Webpage because the read() function returns
It should be noted that to use a webpage in the local domain // the ASCII decimal value and 0
or in the Worldwide Web, the ESP8266 and in turn the (the first decimal number) starts at 48
Arduino must be connected to the internet through a Wi-Fi esp8266.find("pin="); // advance cursor to "pin="
enabled router. The ESP works only when we enter the AT int pinNumber = (esp8266.read()-48)*10;
commands for various functions like sending a message or pinNumber+=(esp8266.read()-48);// get first number i.e.
receiving one. Thus, we make the Arduino do all those if the pin 13 then the 1st number is 1, then multiply to get
chores like opening up a link, connecting to the Access 10
Point, etc.. control(pinNumber);// toggle pin
The following Arduino sketch does just that // make close command
#include <SoftwareSerial.h> String closeCommand = "AT+CIPCLOSE=";
#define DEBUG true closeCommand+=connectionId; // append connection id
SoftwareSerial esp8266(2,3); // make RX Arduino line is closeCommand+="\r\n";
pin 2, make TX Arduino line is pin 3. senddat(closeCommand,1000,DEBUG); // close
// This means that you need to connect the connection
TX line from the esp to the Arduino's pin 2 }
// and the RX line from the esp to the }
Arduino's pin 3 }
void setup() /*
{ Function senddat is used to make the ESP8266 execute the
Serial.begin(9600); required AT commands. It returns a string as prescribed in
esp8266.begin(9600); // your esp's baud rate might be the previous table of AT commands and their responses.
different */
pinMode(4,OUTPUT); String senddat(String command, const int timeout, boolean
digitalWrite(4,LOW); debug)
pinMode(5,OUTPUT); {
digitalWrite(5,LOW); String response = "";
pinMode(6,OUTPUT); esp8266.print(command); // send the read character to the
digitalWrite(5,LOW); esp8266
senddat("AT+RST\r\n",10000,DEBUG); long int time = millis();
senddat("AT+CWMODE=2\r\n",1000,DEBUG); // while( (time+timeout) > millis())
configure as access point {
senddat("AT+CIFSR\r\n",1000,DEBUG); // get ip address while(esp8266.available())

www.ijaems.com Page | 1450


International Journal of Advanced Engineering, Management and Science (IJAEMS) [Vol-2, Issue-9, Sept- 2016]
Infogain Publication (Infogainpublication.com) ISSN: 2454-1311
{ int IRpin = 11,pin3=0,pin4=0,pin2=0,pattern=0;
// The esp has data so display its output to the serial IRrecv irrecv(IRpin);
window decode_results results;
char c = esp8266.read(); // read the next character. void setup()
response+=c; {
} pinMode(12,OUTPUT);
} pinMode(13,OUTPUT);
if(debug) pinMode(4,OUTPUT);
{ pinMode(5,OUTPUT);
Serial.print(response); pinMode(6,OUTPUT);
} digitalWrite(13,HIGH);
return response; digitalWrite(12,LOW);
} Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
/*Function control, to do the required actions on the }
Arduino’s pins when it gets the required responses from the void loop()
exp8266 module through the serial wire. {
*/ if (irrecv.decode(&results))
void control(int a) {
{ Serial.println(results.value, DEC); // Print the Serial
switch(a) 'results.value'
{ irrecv.resume(); // Receive the next value
case 10:digitalWrite(4,!digitalRead(4)); }
break; switch(results.value)
case 11:digitalWrite(5,!digitalRead(5)); {
break; case 33441975:pin4=1;
case 12:digitalWrite(6,!digitalRead(6));
break; break;
case 13:digitalWrite(4,HIGH); case 33456255:pin4=0;
digitalWrite(5,LOW); break;
digitalWrite(6,LOW); case 33446055:pin3=1;
delay(1000); break;
digitalWrite(4,HIGH); case 33439935:pin3=0;
digitalWrite(5,HIGH); break;
digitalWrite(6,LOW); case 33454215:pin2=1;
delay(1000); break;
digitalWrite(4,HIGH); case 33472575:pin2=0;
digitalWrite(5,HIGH); break;
digitalWrite(6,HIGH); default:break;
delay(1000); }
break; if(pin4==1)
default: break; digitalWrite(4,HIGH);
else
} digitalWrite(4,LOW);
} if(pin3==1)
digitalWrite(5,HIGH);
2.6 [5]Controlling Arduino Through Generic IR Remote else
We have also kept a provision to use an IR remote control digitalWrite(5,LOW);
for controlling the home appliances when need be. if(pin2==1)
#include <IRremote.h> digitalWrite(6,HIGH);

www.ijaems.com Page | 1451


International Journal of Advanced Engineering, Management and Science (IJAEMS) [Vol-2, Issue-9, Sept- 2016]
Infogain Publication (Infogainpublication.com) ISSN: 2454-1311
else useWifi();
digitalWrite(6,LOW); useIR();
} inner=analogRead(A4);
outer=analogRead(A5);
2.7 The Final Sketch Including Above Features if(inner<500)
#include <SoftwareSerial.h> {
#include <IRremote.h> B=0;
#define DEBUG true }
SoftwareSerial esp8266(2,3); // make RX Arduino line is else
pin 2, make TX Arduino line is pin 3. {
// This means that you need to connect the B=1;
TX line from the esp to the Arduino's pin 2 }
int c=0; if(outer<500)
int inner=0; {
int outer=0; A=0;
int A=0,B=0; }
int fa=0,fb=0; else
int pin=0; {
int flag=1; A=1;
int flg=0;
int IRpin = 11,pin3=0,pin4=0,pin2=0,pattern=0; }
IRrecv irrecv(IRpin); if(A==0)
decode_results results; {
void setup() fa=1;
{ if(fb==1){c--;}
pinMode(12,OUTPUT); }
pinMode(13,OUTPUT); else
digitalWrite(13,HIGH); {
digitalWrite(12,LOW); fa=0;
Serial.begin(9600); }
esp8266.begin(9600); // your esp's baud rate might be if(B==0)
different {
pinMode(4,OUTPUT); fb=1;
digitalWrite(4,LOW); if(fa==1){c++;}
pinMode(5,OUTPUT); }
digitalWrite(5,LOW); else
pinMode(6,OUTPUT); {fb=0;
digitalWrite(5,LOW); }
senddat("AT+RST\r\n",10000,DEBUG);
senddat("AT+CWMODE=2\r\n",1000,DEBUG); // if(c>0)
configure as access point {
senddat("AT+CIFSR\r\n",1000,DEBUG); // get ip address if(flag == 1)
senddat("AT+CIPMUX=1\r\n",1000,DEBUG); // {
configure for multiple connections pin=1;
senddat("AT+CIPSERVER=1,80\r\n",1000,DEBUG); // control(pin);
turn on server on port 80 }
irrecv.enableIRIn(); }
} else
void loop() {
{ if(flg==0)

www.ijaems.com Page | 1452


International Journal of Advanced Engineering, Management and Science (IJAEMS) [Vol-2, Issue-9, Sept- 2016]
Infogain Publication (Infogainpublication.com) ISSN: 2454-1311
{ }
pin=0; }
control(pin); }
}
flag=1; void IR_decode(int a)
} {
Serial.println(c); switch(a)
} {
void useIR() case 33441975:pin=10;
{ break;
if (irrecv.decode(&results)) case 33446055:pin=11;
{ break;
Serial.println(results.value, DEC); case 33454215:pin=12;
IR_decode(results.value);// Print the Serial break;
'results.value' case 33456255:pin=13;
irrecv.resume(); // Receive the next value break;
flag=0; case 33439935:pin=14;
} break;
} case 33472575:pin=15;
void useWifi() break;
{ case 33431775:pin=0;
if(esp8266.available()) // check if the esp is sending a break;
message case 33480735:pin=1;
{ default:break;
}
control(pin);
if(esp8266.find("+IPD,")) }
{ String senddat(String command, const int timeout, boolean
delay(1000); // wait for the serial buffer to fill up (read debug)
all the serial data) {
// get the connection id so that we can then disconnect String response = "";
int connectionId = esp8266.read()-48; // subtract 48
because the read() function returns esp8266.print(command); // send the read character to the
// the ASCII decimal value and 0 esp8266
(the first decimal number) starts at 48
long int time = millis();
esp8266.find("pin="); // advance cursor to "pin="
while( (time+timeout) > millis())
pin = (esp8266.read()-48)*10; {
pin+=(esp8266.read()-48);// get first number i.e. if the while(esp8266.available())
pin 13 then the 1st number is 1, then multiply to get 10 {
control(pin);// toggle pin
// The esp has data so display its output to the serial
// make close command window
String closeCommand = "AT+CIPCLOSE="; char c = esp8266.read(); // read the next character.
closeCommand+=connectionId; // append connection id response+=c;
closeCommand+="\r\n"; }
sendData(closeCommand,1000,DEBUG); // close }
connection if(debug)
flag=0; {

www.ijaems.com Page | 1453


International Journal of Advanced Engineering, Management and Science (IJAEMS) [Vol-2, Issue-9, Sept- 2016]
Infogain Publication (Infogainpublication.com) ISSN: 2454-1311
Serial.print(response); {
} if(flg==1)
{
return response; if(b==1)
} {
void control(int a) digitalWrite(a,HIGH);
{ }
switch(a) else
{ {
case 10:DecideAndUse(4,1); digitalWrite(a,LOW);
break; }
case 11:DecideAndUse(5,1); flag=0;
break; }
case 12:DecideAndUse(6,1); else
break; {
case 13:DecideAndUse(4,0); digitalWrite(a,LOW);
break; }
case 14:DecideAndUse(5,0); }
break; }
case 15:DecideAndUse(6,0); 2.8 HTML Code
break;
case 16:flg=1; <!DOCTYPE html>
break; <html>
case 17:flg=0; <head>
break; <meta charset="utf-8"/>
case 0: digitalWrite(4,LOW); <title>iCaRE Home Automation</title>
digitalWrite(5,LOW); <<link rel="stylesheet" type="text/css" href="style.css">
digitalWrite(6,LOW); <link rel="stylesheet" href="bootstrap.min.css"/>
break; <link rel="stylesheet" href="font-awesome.min.css">
case 1:digitalWrite(4,HIGH);
digitalWrite(5,HIGH); </head>
digitalWrite(6,HIGH); <body>
break;
default: break; <div class="menu">
}
} <!-- Menu icon -->
void DecideAndUse(int a,int b) <div class="icon-close">
{ <img src="close.png">
if(c>0) </div>
{
if(b==1) <!-- Menu -->
{ <ul>
digitalWrite(a,HIGH); <li><a href="index.html">Home</a></li>
} <li><a href="about_us.html">About</a></li>
else <li><a href="our_vision.html">Our Vision</a></li>
{ <li><a href="help.html">Help</a></li>
digitalWrite(a,LOW); <li><a href="contact.html">Contact</a></li>
} </ul>
} </div>
else

www.ijaems.com Page | 1454


International Journal of Advanced Engineering, Management and Science (IJAEMS) [Vol-2, Issue-9, Sept- 2016]
Infogain Publication (Infogainpublication.com) ISSN: 2454-1311
<!-- Main body --> <div class="row text-center">
<div class="jumbotron"> <h2>Air Conditioning</h2>
<button id="12" class="led">ON</button>
<div class="icon-menu"> <button id="15" class="led">OFF</button>
<i class="fa fa-bars"></i> </div>
Menu <div class="row text-center">
</div> <h2>Remote Control</h2>
<section class="container"> <button id="16" class="led">ON</button>
<div class="row text-center"> <button id="17" class="led">OFF</button>
<h2>Light</h2> <p>Use this Button Only when you want to TURN ON
<button id="10" class="led">ON</button> or OFF your Devices <em>Remotely</em></p>
<button id="13" class="led">OFF</button> </div>
</div> </section>
<div class="row text-center"> <script src="jquery.min.js"></script>
<h2>Fan</h2> <script src="app.js"></script>
<button id="11" class="led">ON</button> </body>
<button id="14" class="led">OFF</button> </html>
</div>

Fig.2.5: Snapshot Of The Webpage

2.9 JS Code
var main = function() { });
$('.icon-close').click(function() {
$('.icon-menu').click(function() { $('.menu').animate({
$('.menu').animate({ left: "-285px"
left: "0px" }, 200);
}, 200);

www.ijaems.com Page | 1455


International Journal of Advanced Engineering, Management and Science (IJAEMS) [Vol-2, Issue-9, Sept- 2016]
Infogain Publication (Infogainpublication.com) ISSN: 2454-1311
$('body').animate({
left: "0px"
}, 200);
});
$(".led").click(function(){
var p = $(this).attr('id'); // get id value (i.e. pin13,
pin12, or pin11)
// send HTTP GET request to the IP address with the
parameter "pin" and value "p", then execute the function
$.get("http://192.168.4.1:80/", {pin:p}); // execute get
request
});
};
$(document).ready(main);
III. CONCLUSION
In conclusion, our device works as expected. We are
expecting to add more and diverse features to take
“automated” to “smart” homes. Going by the trend, this is
going to be the future of clean and smart living. These
devices can run 24x7, 365 days and with a little tweak, we
can also monitor the number of people present. Indirectly,
this can also be used as anti-theft devices to monitor the
home remotely.

REFERENCES
[1] Infra Red Sensor (IR), From the article “Passive
Infrared Sensor”, Wikipedia – The Free Encylopedia.
[2] Arduino, From Arduino Project’s Official Website.
[3] ESP8266, From ESP8266 official website.
[4] AT Commands table as provided in an article
published in itead.cc.
[5] The IR library was used as published in github
directory by username “z3t0”.

www.ijaems.com Page | 1456

You might also like