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

Wireless Attendance System Using NodeMCU with MySQL
Intermediate
  • 606
  • 9

Protip

Here we are going to interface NodeMCU with RFID-RC522 and getting data to phpMyAdmin database.

Attendance System Using MYSQL with Raspberry and RFID-RC522
Intermediate
  • 1,219
  • 9

Protip

Here we are taking data from RFID reader which is connected to Node MCU V3 and saving it to MYSQL database running on Raspberry Pi.

IoT Pet Feeder
Intermediate
  • 6,573
  • 36

Full instructions

Use circuito.io to build a smart food dispenser for your pet controlled directly from your phone.

Autonomous Plant (ESP8266 - Arduino)
Intermediate
  • 39
  • 1

Full instructions

Want to build system that takes care of a plant? Here's my first attempt. Using ESP8266, soil moisture and Sonoff grow light

Smart Pet Feeder
Intermediate
  • 484
  • 5

Work in progress

A smart pet that you can automate, control via Alexa, or even via a web site. Feed your pet any way you want!

Build a Tank Volume Reader in Under $30 using ESP32
Intermediate
  • 752
  • 8

Full instructions

Build a DIY Level Sensor - tank monitor for volume, temperature, and humidity. Prototype for under $30.

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login