Abhishek FalmariSantosh Damranchi
Published © GPL3+

Home Automation Using IOT

Using Internet Of Things we can control our home appliances using Internet or through local area network (LAN).

IntermediateFull instructions provided4 hours2,101
Home Automation Using IOT

Things used in this project

Hardware components

ESP8266 ESP-01
Espressif ESP8266 ESP-01
×1
ftdi cp2102
We can use any other ftdi with 3.3v.
×1
Linear Regulator with Adjustable Output
Linear Regulator with Adjustable Output
×1
Resistor 330 ohm
Resistor 330 ohm
×3
Resistor 221 ohm
Resistor 221 ohm
×1
Resistor 100 ohm
Resistor 100 ohm
×1
Capacitor 100 µF
Capacitor 100 µF
×2
LED (generic)
LED (generic)
×1
Relay (generic)
9v Relay with output specification of 230v AC 7A.
×1
General Purpose Transistor NPN
General Purpose Transistor NPN
×1
1N4007 – High Voltage, High Current Rated Diode
1N4007 – High Voltage, High Current Rated Diode
×1
Male-Header 36 Position 1 Row- Long (0.1")
Male-Header 36 Position 1 Row- Long (0.1")
×1
Female/Female Jumper Wires
Female/Female Jumper Wires
As per required in the peoject.
×1

Software apps and online services

Arduino IDE
Arduino IDE
Notepad++
For designing webpage.

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Hand drill machine

Story

Read more

Custom parts and enclosures

Gerber file for the design of development board for ESP8266-01.

The Gerber files to print on the PCB before itching.

Schematics

Development board.

Image of Development board of Esp8266-01.

Code

Arduino Code for ESP8266-01

Arduino
This file includes the program to be loaded in the ESP8266-01 module using Arduino IDE.
/*
 Home Automation using IOT

 This program controls the gpio pins of ESP8266-01 generic module 
 usint the commands from the internet webpage.

 The commands from the webpage databse is accessed using the 
 JavaScript Object Notation(JSON).

 Created 25 Nov. 2015
 Modified 8 Feb. 2016
 by Abhishek Falmari

 */
#include <ESP8266WiFi.h>
#include <ArduinoJson.h>

const char* ssid     = "Abhishek";  
const char* password = "abhishek2511";

const char* host     = "www.iotabhishekfalamri.netne.net"; // Your domain  
String path          = "/command.json";  
const int pin        = 2;
const int pin1        = 0;
void setup() {  
  pinMode(pin, OUTPUT); 
  pinMode(pin1, OUTPUT);
  pinMode(pin, HIGH);
  pinMode(pin1, HIGH);
  Serial.begin(115200);

  delay(10);
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);
  int wifi_ctr = 0;
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("WiFi connected");  
  Serial.println("IP address: " + WiFi.localIP());
}

void loop() {  
  Serial.print("connecting to ");
  Serial.println(host);
  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }

  client.print(String("GET ") + path + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" + 
               "Connection: keep-alive\r\n\r\n");

  delay(500); // wait for server to respond

  // read response
  String section="header";
  while(client.available()){
    String line = client.readStringUntil('\r');
    . Serial.print(line);
    // we’ll parse the HTML body here
    if (section=="header") { // headers..
      Serial.print(".");
      if (line=="\n") { // skips the empty space at the beginning 
        section="json";
      }
    }
    else if (section=="json") {  // print the good stuff
      section="ignore";
      String result = line.substring(1);

      // Parse JSON
      int size = result.length() + 1;
      char json[size];
      result.toCharArray(json, size);
      StaticJsonBuffer<200> jsonBuffer;
      JsonObject& json_parsed = jsonBuffer.parseObject(json);
      if (!json_parsed.success())
      {
        Serial.println("parseObject() failed");
        return;
      }

      // Make the decision to turn off or on the LED
      if (strcmp(json_parsed["light"], "on1") == 0) {
        digitalWrite(pin1, HIGH); 
        Serial.println("LED ON");
      }
      else if(strcmp(json_parsed["light"], "off1") == 0){
        digitalWrite(pin1, LOW);
        Serial.println("led off");
      } else if(strcmp(json_parsed["light"], "on2") == 0){
        digitalWrite(pin, HIGH);
        Serial.println("led off");
      } else if(strcmp(json_parsed["light"], "off2") == 0){
        digitalWrite(pin, LOW);
        Serial.println("led off");
      }
    }
  }
  Serial.print("closing connection. ");
}

Index page design of the domain.

PHP
The index page code using HTML and PHP for the user interface and to interact with the ESP8266-01 module.
<?php  
$light = $_GET['light'];
if($light == "on1") {  
  $file = fopen("command.json", "w") or die("can't open file");
  fwrite($file, '{"light": "on1"}');
  fclose($file);
} 
else if ($light == "off1") {  
  $file = fopen("command.json", "w") or die("can't open file");
  fwrite($file, '{"light": "off1"}');
  fclose($file);
}
else if($light == "on2") {  
  $file = fopen("command.json", "w") or die("can't open file");
  fwrite($file, '{"light": "on2"}');
  fclose($file);
} 
else if ($light == "off2") {  
  $file = fopen("command.json", "w") or die("can't open file");
  fwrite($file, '{"light": "off2"}');
  fclose($file);
}
?>
 
<html>  
  <head>      
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="keywords" content="footer, address, phone, icons" />
 
 
    <title>LED for ESP8266</title>
 
    <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
	<link rel="stylesheet" href="footer.css">
 
  </head>
  <body>
    <div class="row" style="margin-top: 20px;">
      <div class="col-md-8 col-md-offset-2">
        <a href="?light=on1" class="btn btn-success btn-block btn-lg">ON the LED1</a>
        <br />
		<a href="?light=on2" class="btn btn-success btn-block btn-lg">ON the LED2</a>
        <br />
        <a href="?light=off1" class="led btn btn-danger btn-block btn-lg">OFF the LED1</a>
        <br />
		<a href="?light=off2" class="led btn btn-danger btn-block btn-lg">OFF the LED2</a>
        <br />
        <div class="light-status well" style="margin-top: 5px; text-align:center">
          <?php
            if($light=="on1") {
              echo("LED1 is turned on.");
            }
            else if ($light=="off1") {
              echo("LED1 is turned off.");
            }
			else if($light=="on2") {
              echo("LED2 is turned on.");
            }
            else if ($light=="off2") {
              echo("LED2 is turned off.");
            }
            else {
              echo ("Do something.");
            }
          ?>
        </div>
      </div>
    </div>
 
 
	<footer class="footer-distributed">
 
			<div class="footer-left">
 
				<h3>Abhishek<span>Falmari</span></h3>
 
				<p class="footer-links">
					<a href="/index.php">Home</a>
					.
					<a href="http://www.abhishekfalmari.blogspot.com" target="_blank">My Blog</a>
 
				</p>
 
				<p class="footer-company-name">Group16 &copy; 2016</p>
			</div>
 
			<div class="footer-center">
 
				<div>
					<i class="fa fa-map-marker"></i>
					<p><span>273 A Group</span> Vidi Gharkul, Solapur</p>
				</div>
 
				<div>
					<i class="fa fa-phone"></i>
					<p>+91 8087 878 519</p>
				</div>
 
				<div>
					<i class="fa fa-envelope"></i>
					<p><a href="mailto:support@company.com">abhishek.falmari@gmail.com</a></p>
				</div>
 
			</div>
 
			<div class="footer-right">
 
				<p class="footer-company-about">
					<span>About the Project</span>
					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.
				</p>
 
				<div class="footer-icons">
 
					<a href="https://www.facebook.com/sonu.falmari" target="_blank"><i class="fa fa-facebook"></i></a>
					<a href="https://www.twitter.com/abhishek.falmari" target="_blank"><i class="fa fa-twitter"></i></a>
					<a href="https://www.linkedin.com/profile/view?id=462644220" target="_blank"><i class="fa fa-linkedin"></i></a>
 
				</div>
 
			</div>
 
		</footer>
  </body>
</html>	

CSS design for the index page.

CSS
The CSS code for the index page to be included.
.footer-distributed{
	background-color: #292c2f;
	box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.12);
	box-sizing: border-box;
	width: 100%;
	text-align: left;
	font: bold 16px sans-serif;
 
	padding: 55px 50px;
	margin-top: 80px;
}
 
.footer-distributed .footer-left,
.footer-distributed .footer-center,
.footer-distributed .footer-right{
	display: inline-block;
	vertical-align: top;
}
 
/* Footer left */
 
.footer-distributed .footer-left{
	width: 40%;
}
 
/* The company logo */
 
.footer-distributed h3{
	color:  #ffffff;
	font: normal 36px 'Cookie', cursive;
	margin: 0;
}
 
.footer-distributed h3 span{
	color:  #5383d3;
}
 
/* Footer links */
 
.footer-distributed .footer-links{
	color:  #ffffff;
	margin: 20px 0 12px;
	padding: 0;
}
 
.footer-distributed .footer-links a{
	display:inline-block;
	line-height: 1.8;
	text-decoration: none;
	color:  inherit;
}
 
.footer-distributed .footer-company-name{
	color:  #8f9296;
	font-size: 14px;
	font-weight: normal;
	margin: 0;
}
 
/* Footer Center */
 
.footer-distributed .footer-center{
	width: 35%;
}
 
.footer-distributed .footer-center i{
	background-color:  #33383b;
	color: #ffffff;
	font-size: 25px;
	width: 38px;
	height: 38px;
	border-radius: 50%;
	text-align: center;
	line-height: 42px;
	margin: 10px 15px;
	vertical-align: middle;
}
 
.footer-distributed .footer-center i.fa-envelope{
	font-size: 17px;
	line-height: 38px;
}
 
.footer-distributed .footer-center p{
	display: inline-block;
	color: #ffffff;
	vertical-align: middle;
	margin:0;
}
 
.footer-distributed .footer-center p span{
	display:block;
	font-weight: normal;
	font-size:14px;
	line-height:2;
}
 
.footer-distributed .footer-center p a{
	color:  #5383d3;
	text-decoration: none;;
}
 
 
/* Footer Right */
 
.footer-distributed .footer-right{
	width: 20%;
}
 
.footer-distributed .footer-company-about{
	line-height: 20px;
	color:  #92999f;
	font-size: 13px;
	font-weight: normal;
	margin: 0;
}
 
.footer-distributed .footer-company-about span{
	display: block;
	color:  #ffffff;
	font-size: 14px;
	font-weight: bold;
	margin-bottom: 20px;
}
 
.footer-distributed .footer-icons{
	margin-top: 25px;
}
 
.footer-distributed .footer-icons a{
	display: inline-block;
	width: 35px;
	height: 35px;
	cursor: pointer;
	background-color:  #33383b;
	border-radius: 2px;
 
	font-size: 20px;
	color: #ffffff;
	text-align: center;
	line-height: 35px;
 
	margin-right: 3px;
	margin-bottom: 5px;
}
 
/* If you don't want the footer to be responsive, remove these media queries */
 
@media (max-width: 880px) {
 
	.footer-distributed{
		font: bold 14px sans-serif;
	}
 
	.footer-distributed .footer-left,
	.footer-distributed .footer-center,
	.footer-distributed .footer-right{
		display: block;
		width: 100%;
		margin-bottom: 40px;
		text-align: center;
	}
 
	.footer-distributed .footer-center i{
		margin-left: 0;
	}
 
}
 

Credits

Abhishek Falmari

Abhishek Falmari

1 project • 6 followers
I'm an electronics and software geek, an extrovert, foodie, fitness conscious, and many more.
Santosh Damranchi

Santosh Damranchi

1 project • 2 followers

Comments