IOT based home automation project

 We live in an exciting time where more and more everyday items “things” are becoming smart!  “Things” have sensors and can communicate to other “things” and can provide control to more “things”.  The Internet of Things, IoT, is upon us in a huge way and people are rapidly inventing new gadgets that enhance our lives.  The price of microcontrollers with the ability to talk over a network keeps dropping and developers can now tinker and build things inexpensively.

IoT based home automation project is done using low cost ESP8266 ESPino ESP-12 WiFi Module, It uses relays and few simple components, complete code is provided, for more details on software setup go through IoT getting started tutorial. You can control four electrical devices and also you can monitor temperature. ESP-12 is low cost module we are using here.

Iot home automation Block Diagram
Block Diagram

Components Required

Buy Complete Project or PCB from shop.circuits4you.com

1. ESP-12 WiFi Module
2. LM1117-3.3V
3. Sugar Cube Relay – Qty.4
4. Resistors 10K, 1K,4.7K
5. Capacitor 1000uF, 10uF, 104 (0.1uF)
6. PBT-2 Connectors Qty. 5
7. ULN2003
8. 12V Power Supply

With advancement of Automation technology, life is getting simpler and easier in all aspects. In today’s world Automatic systems are being preferred over manual system. With the rapid increase in the number of users of internet over the past decade has made Internet a part and parcel of life, and IoT is the latest and emerging internet technology. Internet of things is a growing network of everyday object-from industrial machine to consumer goods that can share information and complete tasks while you are busy with other activities. Wireless Home Automation system(WHAS) using IoT is a system that uses computers or mobile devices to control basic home functions and features automatically through internet from anywhere around the world, an automated home is sometimes called a smart home. It is meant to save the electric power and human energy. The home automation system differs from other system by allowing the user to operate the system from anywhere around the world through internet connection.

IoT Home Automation Circuit Diagram

From the circuit diagram it is very clear that we have used few components, LM1117-3.3V is used for providing power supply to the ESP-12 WiFi Module. ULN2003 provides relay driving.

iot based home autoamtion circuit
Circuits Diagram

PCB Layout of Home Automation

PCB Layout IoT Home Automation
PCB Layout IoT Home Automation

Download IOT Home Automation PCB Layout pdf

BUY THIS PROJECT

IoT Based Home Automation Code

main.c
/*
 * Copyright (c) 2015, circuits4you.com
 * All rights reserved.
/* Create a WiFi access point and provide a web server on it. */

#include <ESP8266WiFi.h>
#include <WiFiClient.h> 
#include <ESP8266WebServer.h>

#include "mainPage.h"

const int Load1=16;
const int Load2=14;
const int Load3=12;
const int Load4=13;

/* Set these to your desired credentials. */
const char *ssid = "HomeServer";
const char *password = "homeautomation";

ESP8266WebServer server(80);
String L1Status,L2Status,L3Status,L4Status,Temperature;
//=======================================================================
//                    handles main page 192.168.4.1
//=======================================================================
/* Just a little test message.  Go to http://192.168.4.1 in a web browser
 * connected to this access point to see it.
 */
void handleRoot() {
  String s = MAIN_page;    
  s.replace("@@L1@@", L1Status);
  s.replace("@@L2@@", L2Status);
  s.replace("@@L3@@", L3Status);
  s.replace("@@L4@@", L4Status);
  s.replace("@@TEMP@@", Temperature);
  server.send(200, "text/html", s);    
}

//=======================================================================
//                    Handle Set Date/Time Settings
//=======================================================================
void handleForm() {
  String t_state = server.arg("submit");
  
  Temperature = String(analogRead(A0)/10);   //Do calibration here
  
//Change Load-1 State as per request
  if(t_state=="ON1")
  {
    L1Status="ON";    
    digitalWrite(Load1, HIGH);       //Load1 Turned on
  }
  
  if(t_state=="OFF1")
  {
    L1Status="OFF";    
    digitalWrite(Load1, LOW);      //Load1 Turned off  
  }
//Change Load-2 State as per request
  if(t_state=="ON2")
  {
    L2Status="ON";    
    digitalWrite(Load2, HIGH);       //Load1 Turned on
  }
  
  if(t_state=="OFF2")
  {
    L2Status="OFF";    
    digitalWrite(Load2, LOW);      //Load1 Turned off  
  }
//Change Load-3 State as per request
  if(t_state=="ON3")
  {
    L3Status="ON";    
    digitalWrite(Load3, HIGH);       //Load1 Turned on
  }
  
  if(t_state=="OFF3")
  {
    L3Status="OFF";    
    digitalWrite(Load3, LOW);      //Load1 Turned off  
  }
//Change Load-4 State as per request
  if(t_state=="ON4")
  {
    L4Status="ON";    
    digitalWrite(Load4, HIGH);       //Load1 Turned on
  }
  
  if(t_state=="OFF4")
  {
    L4Status="OFF";    
    digitalWrite(Load4, LOW);      //Load1 Turned off  
  }

  server.sendHeader("Location", "/");
  server.send(302, "text/plain", "Updated-- Press Back Button");  //This Line Keeps It on Same Page
   
  delay(500);
}
//=======================================================================
//                    Power on setup
//=======================================================================

void setup() {
  delay(1000);
  /* You can remove the password parameter if you want the AP to be open. */
  WiFi.softAP(ssid, password);

  IPAddress myIP = WiFi.softAPIP();
  server.on("/", handleRoot);
  server.on("/form", handleForm);
 
  server.begin();
  pinMode(Load1, OUTPUT);
  pinMode(Load2, OUTPUT);
  pinMode(Load3, OUTPUT);
  pinMode(Load4, OUTPUT);  
}

//=======================================================================
//                    Main Program Loop
//=======================================================================
void loop() {
  server.handleClient();
}
//=======================================================================
mainPage.h
const char MAIN_page[] PROGMEM = R"=====(
<HTML>
<TITLE>
REMOTE LED ON/OFF CONTROL
</TITLE>
<BODY>
<CENTER>
<FORM method="post" action="/form">
<TABLE>
<TR><TD colspan=2><B>IoT Based Home Automation System</B></TD></TR>
<TR><TD>Temp: @@TEMP@@ C</TD><TD>Load Status</TD></TR>

<TR><TD>
<INPUT TYPE=SUBMIT VALUE="ON1" name=submit>
<INPUT TYPE=SUBMIT VALUE="OFF1" name=submit>
</TD>
<TD>@@L1@@</TD></TR>

<TR><TD>
<INPUT TYPE=SUBMIT VALUE="ON2" name=submit>
<INPUT TYPE=SUBMIT VALUE="OFF2" name=submit>
</TD>
<TD>@@L2@@</TD></TR>

<TR><TD>
<INPUT TYPE=SUBMIT VALUE="ON3" name=submit>
<INPUT TYPE=SUBMIT VALUE="OFF3" name=submit>
</TD>
<TD>@@L3@@</TD></TR>

<TR><TD>
<INPUT TYPE=SUBMIT VALUE="ON4" name=submit>
<INPUT TYPE=SUBMIT VALUE="OFF4" name=submit>
</TD>
<TD>@@L4@@</TD></TR>


<TR><TD colspan=2><B><CENTER><A href = "https://circuits4you.com">www.circuits4you.com</a></CENTER></B></TD></TR>
</TABLE>
</FORM>

</CENTER>
</BODY>
</HTML>
)=====";

 

BUY THIS PROJECT

 

IoT based Home Automation Circuit Testing

1. Turn on the circuit
2. Turn on WiFi on your mobile or Laptop
3. Enter 192.168.4.1 Ip in browser
4. You will find this page and operate the relays
5. Connect Relay output to the electrical load

iot home automation results
Web Page in browser

This is the simplest IOT Based Home Automation uses only ESP8266 Low cost iot module and relays.

20 thoughts on “IOT based home automation project

    1. You can enable Both AP and STA mode. Just make sure you are using different names (just for identification same works) for AP, And your router. and another is don’t wait for connection in while loop.
      This way you can have both

      WiFi.mode(WIFI_AP_STA); //Both hotspot and client are enabled
      WiFi.softAP(ssid, password);

      //Optional if both are required
      WiFi.begin(ssid, password); //Conects to WiFi router tries every 1 second

      //NO While loop waiting for connection status

  1. What is that connection in PCB layout which is on 1000uf capacitor and connected with positive of capacitor C2?

    What is J3 here and how to upload the code in ESP-12?

    Please reply asap.

  2. Thanks for the project.
    You have a small error in the code.
    When you turn on the load set the high state,
    even after switching off the load set the high state,
    should be low.

  3. Thanks for the project. Your circuit diagram and BOM is a little bit hard to follow though –
    1) what is RD1?
    2) I assume IC1 is your LM1117?

    1. Thanks Joe for pointing the issue, Now you can get pdf file for PCB Development and Large circuit diagram when you click it

      RD1 is 1N4007 Diode for reverse polarity protection, IC1 is LM1117-3.3 that’s correct

      One more thing use LM7805 in series with LM1117, giving directly 12V to LM1117-3.3 will cause over heating issue.

  4. Hi every one. I have 5 of esp8266 module 3 in esp8266-01 and 2 in nodemcu 8266 I tried different way to run it but i don’t know why I couldn’t do it. I use different suggestions to run but I could not. really I heat this device and the factory witch made such a module. as I see this is not only my problem and many more people have problem such me. so who can help me solve I don’t know by now you may can I will appreciate you if you do so.
    thanks and best regards

Leave a Reply