Shubham Devkar
Published © GPL3+

Home Automation

This project is home automation through IoT.

IntermediateWork in progress1 hour1,661
Home Automation

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
LED (generic)
LED (generic)
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
RobotGeek Relay
RobotGeek Relay
×1

Software apps and online services

Arduino IDE
Arduino IDE

Code

IOT BASED HOME AUTOMATION

Arduino
IOT BASED HOME AUTOMATION USING NODE-MCU ESP8266 WIFI MODULE.
#include <ESP8266WiFi.h> 
const char* ssid = "Astro's Miracle";
const char* password = "password";
 // 
WiFiServer server(80);
 
void setup() 
{
  Serial.begin(115200);
  delay(10);
  pinMode(4, OUTPUT);
  digitalWrite(4, LOW);
  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
 
  // Start the server
  server.begin();
  Serial.println("Server started");
 
  // Print the IP address
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");
 
}
 
void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
 
  // Wait until the client sends some data
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }
 
  // Read the first line of the request
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();
 
  // Match the request
 
 

   if (request.indexOf("/light2on") > 0)  {
    digitalWrite(4, LOW);
   
  }
  if (request.indexOf("/light2off") >0)  {
    digitalWrite(4, HIGH);
   
  }
 // Set ledPin according to the request
//digitalWrite(ledPin, value);
 
  // Return the response
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println(""); //  do not forget this one
  client.println("<!DOCTYPE HTML>");
  client.println("<html>");
  client.println("<head>");
  client.println("<meta name='apple-mobile-web-app-capable' content='yes' />");
  client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
 client.println("</head>");
  client.println("<body bgcolor = \"#f7e6ec\">"); 
  client.println("<hr/><hr>");
  client.println("<h4><center> Team Astro :Esp8266 Electrical Device Control </center></h4>");
  client.println("<hr/><hr>");
  client.println("<br><br>");
  client.println("<br><br>");
  client.println("<center>");
  client.println("LED LIGHT");
  client.println("<a href=\"/light2on\"\"><button>Turn On </button></a>");
  client.println("<a href=\"/light2off\"\"><button>Turn Off </button></a><br />");  
  client.println("</center>"); 
  client.println("<br><br>");
  client.println("<center>"); 
  client.println("<table border=\"5\">");
   client.println("<tr>");
    if (digitalRead(4))
          { 
           client.print("<td>Light  is OFF</td>");

         }
          else
          {

            client.print("<td>Light  is ON</td>");

          }
          client.println("</tr>");

         client.println("</table>");

          client.println("</center>");
  client.println("</html>"); 
  delay(1);
  Serial.println("Client disonnected");
  Serial.println("");
 
}

Credits

Shubham Devkar

Shubham Devkar

13 projects • 14 followers
Experienced Electronics engineer, excellent at PCB Designing, control circuit development.circuit designing, hands-on experience with MCUs

Comments