Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
199 views

Home Automation Using Arduino and ESP8266 Module

Uploaded by

Ashok kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
199 views

Home Automation Using Arduino and ESP8266 Module

Uploaded by

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

12/13/2019 Home Automation using Arduino and ESP8266 Module

HOME / PROJECTS, EMBEDDED, ARDUINO, IOT, ESP8266 / HOME AUTOMATION USING ARDUINO AND ESP8266 MODULE

Home Automation using Arduino and ESP8266 Module

Availability Solution for AHV


Enterprise-class scalability and operational simplicity for all applications and
data!

Veeam Software DOWNLOAD

30 Home Automation using Arduino and ESP8266 Module


Dec  By Ali Hamza  Arduino, Embedded, ESP8266, IoT, Projects  Arduino, Automation, ESP-01, ESP8266, IoT  30 Comments

In this project we are going to make a home automation system using ESP8266 WiFi module
Contents
and Arduino Uno. Using this we will be able to control lights, electric fan and other home
appliances through a web browser using your PC or mobile. These AC mains appliances will be 1 ESP-01 ESP8266 Module
connected to relays which are controlled by the Arduino. ESP8266 and Arduino together acts as 2 Circuit Diagram and Explanation
a Web Server and we will send control commands through a Web Browser like Google Chrome 3 Program
or Mozilla Firefox. ESP8266 is the one of the most popular and low cost wi module available in 3.1 Arduino Sketch
the market today. You can ready more about it here, ESP8266 – WiFi SoC. 3.1.1 Explanation
3.2 HTML Code
3.2.1 jQuery
ESP-01 ESP8266 Module 3.2.2 Explanation
4 How to make it work ?
5 Video
ESP-01 is the one of the most popular ESP8266
module available in the market. ESP8266 is a self
contained SoC with integrated TCP/IP stack which helps any microcontroller having UART
to access a wi network. It can act as both WiFi access point as well as a WiFi client. It is
pre-programmed with AT commands, so we can easily access and con gure it using a
microcontroller.

ESP8266 runs on 3.3V and its input pins are not 5V tolerant. So we need to reduce the 5V
output of the Arduino Tx pin to 3.3V by using voltage dividing resistors to connect to Rx
pin of ESP8266 module. Arduino TTL input pins will detect 3.3V as logic high, so we can
directly connect 3.3V output of ESP8266 Tx to Arduino Rx pin.

Circuit Diagram and Explanation


ESP-01 ESP8266 Module

https://electrosome.com/home-automation-arduino-esp8266/ 1/13
12/13/2019 Home Automation using Arduino and ESP8266 Module

Home Automation System using Arduino and ESP8266 – Circuit Diagram

First we can connect ESP8266 with the Arduino Uno. The ESP8266 runs on 3.3V, it may damage if you connect it directly to 5V from
Arduino. The pin out of the ESP-01 ESP8266 module is shown below.

Connect the VCC and CH_PD of the ESP8266 to the 3.3V output pin of Arduino.
CH_PD is Chip Power Down pin, which is active low. So we will give 3.3V to it,
which will enable the chip. Then connect the TXD pin of the ESP8266 with the
digital pin 2 of the Arduino. Then make a voltage divider to make 3.3V for the
RXD of the ESP8266 which is connected  to the pin 3 of Arduino. Here we are
using software UART through digital pins 2 & 3 of Arduino. Lastly, connect the
ground of the ESP8266 with the ground of the Arduino.
ESP-01 ESP8266 Module Pinout
Now we can connect relays to Arduino. Connect three relays to pins 11, 12 and
13 of the Arduino. Also connect 5V and ground from the Arduino to power the relay. Note that here I am using relay modules which
having built in transistor driver. So don’t forget to add driver when you are using bare relays. We can connect AC devices to the
output terminals of those relays. First connect one wire (Phase) of the AC source with the common terminal (COM) of all relays and
the second wire (Neutral) of AC source to one terminal of AC devices. Then connect the other terminal of AC devices to the NO
(Normally Open) terminal of relays.

Program
Arduino Sketch

https://electrosome.com/home-automation-arduino-esp8266/ 2/13
12/13/2019 Home Automation using Arduino and ESP8266 Module

#include <SoftwareSerial.h> //Including the software serial library


#define DEBUG true
SoftwareSerial esp8266(2,3); // This will make the Arduino pin 2 as the RX pin and Arduino pin 3 as the TX. Software UART
/* So you have to connect the TX of the esp8266 to the pin 2 of the Arduino and the TX of the esp8266 to the pin 3 of the
Arduino. This means that you need to connect the TX line from the esp to the Arduino's pin 2 */

void setup()
{
Serial.begin(9600); // Setting the baudrate to 9600
esp8266.begin(9600); // Set it according to your esp’s baudrate. Different esp’s have different baud rates.
pinMode(11,OUTPUT); // Setting the pin 11 as the output pin.
digitalWrite(11,LOW); // Making it low.
pinMode(12,OUTPUT); // Setting the pin 12 as the output pin..
digitalWrite(12,LOW); // Making pin 12 low.
pinMode(13,OUTPUT); // Setting the pin 13 as the output pin.
digitalWrite(13,LOW); // Making pin 13 low.
sendData("AT+RST\r\n",2000,DEBUG); //This command will reset module to default
sendData("AT+CWMODE=2\r\n",1000,DEBUG); // This will configure the mode as access point
sendData("AT+CIFSR\r\n",1000,DEBUG); // This will get ip address and will show it
sendData("AT+CIPMUX=1\r\n",1000,DEBUG); // This will configure the ESP8266 for multiple connections
sendData("AT+CIPSERVER=1,80\r\n",1000,DEBUG); // This will set the server on port 80
}
void loop()
{
if(esp8266.available()) // Checking that whether the esp8266 is sending a message or not (Software UART Data)
{
if(esp8266.find("+IPD,"))
{
delay(1000); // Waiting for 1 sec
int connectionId = esp8266.read()-48; // Subtracting 48 from the character to get the number.
esp8266.find("pin="); // Advancing the cursor to the "pin="
int pinNumber = (esp8266.read()-48)*10; // Getting the first number which is pin 13
pinNumber += (esp8266.read()-48); // This will get the second number. For example, if the pin number is 13 then the
2nd number will be 3 and then add it to the first number
digitalWrite(pinNumber, !digitalRead(pinNumber)); // This will toggle the pin
// The following commands will close the connection
String closeCommand = "AT+CIPCLOSE=";
closeCommand+=connectionId;
closeCommand+="\r\n";
sendData(closeCommand,1000,DEBUG); // Sending the data to the ESP8266 to close the command
}
}
}
String sendData(String command, const int timeout, boolean debug) // Function to send the data to the esp8266
{
String response = "";
esp8266.print(command); // Send the command to the ESP8266
long int time = millis();
while( (time+timeout) > millis()) // ESP8266 will wait for some time for the data to receive
{
while(esp8266.available()) // Checking whether ESP8266 has received the data or not
{
char c = esp8266.read(); // Read the next character.
response+=c; // Storing the response from the ESP8266
}
}
if(debug)
{
Serial.print(response); // Printing the response of the ESP8266 on the serial monitor.
}
return response;
}

Explanation
The code is very long but easy to understand as it is well commented. First we will initialize the software uart with digital pins 2 & 3
of Arduino for the communication with ESP8266. After that we will initialize pins to which we will connect relays as output pins. Then
we will con gure ESP8266 in access point mode. Arduino + ESP8266 is programmed as a web server such that we can control those 

https://electrosome.com/home-automation-arduino-esp8266/ 3/13
12/13/2019 Home Automation using Arduino and ESP8266 Module

relays through a web browser.

HTML Code
<html>
<head>
<title>Home Automation System</title> <!-- This will be the page title -->
</head>
<body> <!-- All the data in it will be shown on the page -->
<button id="11" class="led">Toggle Pin 11</button> <!-- This will create the button for pin 11 -->
<button id="12" class="led">Toggle Pin 12</button> <!-- This will create the button for pin 12 -->
<button id="13" class="led">Toggle Pin 13</button> <!-- This will create the button for pin 13 -->

<script src="jquery.min.js"></script> <!-- This will read the script from the jquery -->
<script type="text/javascript">
$(document).ready(function(){
$(".led").click(function(){
var p = $(this).attr('id'); // Getting the id value that which pin to toggle, pin 13 or pin 13 or pin 11
// Sending the request to the ip address of the server with the pin number to toggle the
pin
$.get("http://192.168.4.1:80/", {pin:p}); // Sending the get request
});
});
</script>
</body>
</html>

jQuery
The above HTML code uses the open source javascript library JQuery, so we need to obtain that. You can get it from this link and
save it by right clicking on it. Save it in the same directory where you are going to save the above HTML code. Save the JQuery library
le as the jquery.min and the full name of the le will be “jquery.min.js”.

Then copy above HTML code in a le and save it as an HTML le, say ‘control.html’. You can open this HTML le in a web browser,
which will looks as shown below.

Home Automation Arduino ESP8266 – Web Page

Explanation
Whenever a button is pressed in the web browser,  a HTTP GET request is send to the Arduino-ESP8266 webserver to toggle a
particular pin. In the Arduino code, it looks for the string “+IPD” again and again to check that if any request is coming or not. When
it gets a request it reads the next character which is the connection id. Connection id is required to close the particular TCP
connection after processing the request. Then it looks for the pin number to toggle by checking the character after the string “?pin=”.
The Arduino then toggles that particular digital pin, which toggles the relay.

https://electrosome.com/home-automation-arduino-esp8266/ 4/13
12/13/2019 Home Automation using Arduino and ESP8266 Module

Home Automation System using Arduino and ESP8266

How to make it work ?


After uploading the code to the Arduino, open the serial monitor from the Arduino IDE. It will show you the IP address as shown
below.

ESP8266 – Arduino Web Server – IP Address

First connect your system to the access point created by ESP8266 module (ESP_xxxxxx). Update  the IP address in the
control.html le created above. Now open the le using your web browser (Google Chrome or Mozilla Firefox). Now you can control
your home appliances very easily.

Note : You may change the default SSID (ESP_xxxxxx) of ESP8266 WiFi module by using AT+CWSAP command.

Video

https://electrosome.com/home-automation-arduino-esp8266/ 5/13
12/13/2019 Home Automation using Arduino and ESP8266 Module

Home Automation System using Arduino and ESP8266

Related Posts:

Getting Started with


Connecting ESP8266 IoT Data Logger ESP8266 Digital Thermometer
Arduino Weather to WiFi Network – using Arduino and Programming – using LM35 Sensor
Station Web Server Beginners Guide ESP8266 Arduino and ESP8266

LED Control by Web Controlled Temperature


ESP8266 as Web Servo Motor – Controlled Fan using
Server – IoT Arduino –… Arduino

 Share this post

    

 Author
Ali Hamza

https://electrosome.com/home-automation-arduino-esp8266/ 6/13
12/13/2019 Home Automation using Arduino and ESP8266 Module

 Comments (30)

Toobeeraj Panchoo
Hello, I would like to have a full circuit including the breadboard with its resistors and more on this home automation,
anyone please its terribly urgent
January 21, 2017 at 10:57 am

Toobeeraj Panchoo
where u got UART software
January 21, 2017 at 11:37 am

Jon Arotzarena
Can you provide details on ashing the esp8266? What do I need to do to get the ESP to connect to my home network?
February 1, 2017 at 12:39 am

Ayodeji
Can i use a 4 channel relay for this project. (4 Channel 5V Relay Module 10A)
February 22, 2017 at 4:03 pm

Lim Wsing
how to design ESP8266 using protues software?
February 23, 2017 at 6:22 pm

ASHIK LAL
HI,i had tried this
everything is alright but my esp-01 is not showing anything after opening serial monitor what can i do relays are on when
connecting power supply
March 31, 2017 at 11:35 am

Wejdan
I faced the same problem
did you solve it?
April 15, 2017 at 9:27 pm

Ken
can html in esp8266?
April 21, 2017 at 11:04 pm

berlin benilo
sir,when a DC source was provided instead of this Ac source by connecting with the DC motor and bulb for an mini level
project,did any fault obtained for the design….?.please answer me sir
August 22, 2017 at 11:02 pm

sanjaysan
it can be controlled by any android apps
September 22, 2017 at 10:28 pm

https://electrosome.com/home-automation-arduino-esp8266/ 7/13
12/13/2019 Home Automation using Arduino and ESP8266 Module

sanjaysan
it can be controlled by any apps
September 22, 2017 at 10:48 pm

Abdul Rehman
I want to control 8 relays and controll it by android app
October 4, 2017 at 4:33 pm

shubham rajguru
no prolem to do this .i also do this mini project
December 5, 2017 at 7:24 pm

Syed Faizan Abuzar


Not Much Explanation…………
December 28, 2017 at 1:16 am

Ligo George
Try this : https://electrosome.com/home-automation-bluetooth-mobile-app/
December 28, 2017 at 9:57 am

Ganesh
Sir, I getting the Warnings in the Arduiono Sketch.
:My Project FilesAruinoProgram8266sketch_jan08bsketch_jan08b.ino:26:28: warning: deprecated conversion from string
constant to ‘char*’ [-Wwrite-strings]
if(esp8266. nd(“+IPD,”))
^
January 8, 2018 at 4:07 pm

somnath panja
https://uploads.disquscdn.com/images/e3d442748079ca056a4a432861aed82e148bae0c306b40044bc580c57192424c.png
https://uploads.disquscdn.com/images/2c66cd5e116863bd1d63e0a446e5966e514ef36b94ec5cbbc3ab7bfe8157344a.png
do not come ip address…why ??? arduino program is ok ????
January 10, 2018 at 11:08 am

Vidit Naithani
Dude how did you solve this problem
February 11, 2018 at 10:46 pm

Pramod Bhogi
hloo sir,
I executed this programme,but nothing is showing for me on serial monitor.
so what to do..?
February 14, 2018 at 7:54 pm

Dahen Ece
why my esp does not show anything to serial monitor and also it does not response to any command!
February 21, 2018 at 1:00 am

Omar Akar
hi , I’m working on a senior project which i can control the controller of hdmi switch by using relays and arduino , I connect
the wires as the picture above , and copied the arduino code , but there is no output on serial monitor . what is the problem
? thank you . 

https://electrosome.com/home-automation-arduino-esp8266/ 8/13
12/13/2019 Home Automation using Arduino and ESP8266 Module

May 29, 2018 at 2:56 am

david K
Instead of using pin number {pin:p} directly in the code i want to activate it by a code. Say when i send “onrelay1” it should
activate pin.
E.g 192.168.4.1/?pin=onrelay1
Instead of 192.168.4.1/?pin=11
June 28, 2018 at 6:23 pm

Somto Akuekwe
i must thank you for such a wonderful project. Please can this be used to control relays from as far o as a persons o ce
June 28, 2018 at 7:31 pm

Karthik Raja
Hi for me also the serial monitor showing empty…
How you upload the program? Is Esp-01 module need to be program separately and arduino program seperately???
Or Is the given single programm enough?
Can you please explain in detail for programming steps
July 7, 2018 at 8:25 pm

abdul gha ar
i am getting the same blank serial monitor…can some help me please…
August 1, 2018 at 11:17 am

chetan gautam
hello sir ,
I want to get IP address without using serial PORT . How can we do this. If is it possible . Can we print on Web page.
September 12, 2018 at 3:24 pm

achu s
sir tell me if controll fan speed externally with regulator at same time ..how can poosible???
February 4, 2019 at 10:54 pm

achu s
give some ideas
February 4, 2019 at 10:54 pm

Mahesh b
We are not getting the IP address . Please explain how to get it
March 28, 2019 at 5:28 pm

manu
hi,
I am getting this error:
ssize_t’ does not name a type ssize_t m_swsInstsIdx = -1;
when i try to Verify the above code you have given..Please help to solve ASAP
June 21, 2019 at 12:22 pm

Leave a Reply

Your email address will not be published. Required elds are marked *

https://electrosome.com/home-automation-arduino-esp8266/ 9/13
12/13/2019 Home Automation using Arduino and ESP8266 Module

Comment

Name *

Email *

Website

Save my name, email, and website in this browser for the next time I comment.

POST COMMENT

RELATED POSTS

Digital Digital Door Lock Digital Clock using Sendin


Thermometer using Arduino PIC Microcontroller from ES
using Arduino and December 10, 2016 | Ali Hamza | and DS1307 RTC IoT Pro
Arduino, Embedded, Projects |
DS18B20 Sensor Arduino, Keypad, Lock | 15 May 31, 2012 | Ligo George | January 17, 2
Comments Embedded, PIC Microcontroller, Electronics, E
June 7, 2017 | Ali Hamza | Projects | Clock, Digital, DS1307, IoT, Projects
Arduino, Embedded, Projects | As thefts are increasing day by day
Embedded, Microcontroller, PIC, base64encod
Arduino, Arduino Uno, DS18B20, security is becoming a major
RTC | 319 Comments ESP8266, IoT
concern nowadays. In this project
GLCD, LCD, Nokia 5110 | 0 Server | 0 Co
we will... A Digital Clock can be made easily
Comments
by using PIC Microcontroller, The scope of
Read More 
In this project, we are going to DS1307 and a 16x2 LCD. I have is growing fr
make a Digital Thermometer using already... appliances to
Arduino Uno. We will use DS18B20 (like sensors
temperature... Read More 
mails. So...

Read More  Read More 

RECENT POSTS

Installing Keil IDE – ARM Microcontroller Tutorial – Part 1 

https://electrosome.com/home-automation-arduino-esp8266/ 10/13
12/13/2019 Home Automation using Arduino and ESP8266 Module

October 8, 2019

Sending E-mail from ESP8266 – IoT Project


January 17, 2019

Controlling LED using ESP8266 and Telegram Bot – IoT Project


December 21, 2018

Interfacing MPU-6050 / GY-521 board with Arduino Uno


December 16, 2018

Updating Sensor Data to Google Spreadsheet using ESP8266 – IoT Project


November 28, 2018

Flashing Espressif and NodeMCU Firmware to ESP8266


October 28, 2018

FOLLOW US

  

MOST VIEWED

Astable Multivibrator using Transistors


by Ligo George

Getting Started with MPLAB XC8 Compiler – LED Blinking


by Ligo George

LED Blinking using 8051 Microcontroller and Keil C – AT89C51


by Ebin George

What is a Microprocessor ?
by Ligo George

5V Power Supply using 7805 Voltage Regulator with Design


by Manoj Shenoy

Transistor as a Switch
by Ligo George

CATEGORIES

 Electronics

 555 Circuits

 Basic Electronics

https://electrosome.com/home-automation-arduino-esp8266/ 11/13
12/13/2019 Home Automation using Arduino and ESP8266 Module

 Opamp

 Electronics News

 IC

 Power Supply

 Sensors

 What is Inside?

 Featured

 Mobiles

 News

 Processors

 Projects

 Embedded

 Arduino

 AVR Microcontroller

 ESP8266

 PIC Microcontroller

 Hobby Circuits

 IoT

 Softwares

 Tablets

 Technology Transfer

 Tutorials

 8051 Microcontroller

 8085

 Arduino

 ARM

 ARM7

 ATMEL AVR

 CloudX

 ESP8266

 MATLAB

 OpenWrt

 PCB Designing

 DipTrace

 OrCad

 PIC Microcontroller

 CCS C Compiler

 Hi-Tech C

 MikroC

 MPLAB XC8

 Python
https://electrosome.com/home-automation-arduino-esp8266/ 12/13
12/13/2019 Home Automation using Arduino and ESP8266 Module

 Raspberry Pi

 Python Rpi

 SCILAB

MOST COMMENTED

Digital Clock using PIC Microcontroller and DS1307 RTC


by Ligo George

Voltmeter and Ammeter using PIC Microcontroller


by Ligo George

Water Level Indicator and Controller using PIC Microcontroller


by Ligo George

Interfacing HC-SR04 Ultrasonic Sensor with PIC Microcontroller


by Ligo George

Automatic Power Factor Controller using Microcontroller


by Divya Syamala

USB PIC Programmer : PICKit2


by Ligo George

TAGS

3D 16F877A 555 8051 MICROCONTROLLER ANDROID ARDUINO ARDUINO UNO ATMEGA32 ATMEL DC MOTOR DHT22

ELECTRONICS EMBEDDED ESP8266 GOOGLE HI-TECH C IOT L293D LCD LED MATLAB MICROCONTROLLER MIKROC

MOBILE MOTOR MPLAB MPLAB XC8 OP-AMP PCB PIC PROTEUS PWM PYTHON RASPBERRY PI RFID SAMSUNG

SENSOR SENSORS SERVO MOTOR SMARTPHONE TABLET TRANSISTOR TRANSISTORS TUTORIALS XC8

RECENT COMMENTS

 Chand Sayyad on Transformerless Capacitor Dropper Power Supply

 Shani on Interfacing DC Motor with PIC Microcontroller using L293D

 Rendon Gree on Using UART on Raspberry Pi – Python

 Rendon Gree on Using UART on Raspberry Pi – Python

 B B DWIVEDI on What is a Microprocessor ?

FOLLOW US

   

© Copyright 2018. All Rights Reserved.

https://electrosome.com/home-automation-arduino-esp8266/ 13/13

You might also like