Things used in this project

Hardware components:
Nodemcu
NodeMCU ESP8266 Breakout Board
×1
09590 01
LED (generic)
×1
826 04
Male/Female Jumper Wires
×1
Rg relay a
RobotGeek Relay
×1
Software apps and online services:
Ide web
Arduino IDE

Code

IOT BASED HOME AUTOMATIONArduino
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

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

WiDC: Wi-Fi-Controlled FPV Robot
Intermediate
  • 4,981
  • 32

Full instructions

What about using a Wi-Fi remote-controlled robot for exploring your surroundings, reaching inaccessible places, spying and take pictures?

Smart Garden
Intermediate
  • 600
  • 5

Smart Garden is plant environmental monitoring system.

WiFi Messenger
Intermediate
  • 275
  • 4

Protip

Calling my son from his room using 2 ESP8266 modules, instead of shouting.

IoT Thermometer Using Python
Intermediate
  • 198
  • 2

Full instructions

How to develop a simple, but powerful, IoT thermometer using a Zerynth-powered single-board MCU and the Zerynth App.

Counting Pulses with Maxim DS1682
Intermediate
  • 64
  • 2

Protip

This project is interfacing the Energy Monitoring system with a pulse counter.

IoT-Based Healthcare
Intermediate
  • 482
  • 16

Full instructions

It is about a wearable device which senses temperature and heart beat and sends it to mobile app or web app. Patient monitoring or self use.

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login
Feedback