HOMEAUTOMATION_OVER_WIFI||Part_2

 


Hey everyone,

My name is Amey and I am back with another project, this is the part two of Home automation Series if You are new here than check the first part (HERE) In first part I blink an LED over my WIFI using web browser, this time I am making an Application which control the actual AC Light over my WIFI.

I gather all the component and start making it.

So, let’s make it!!!!

 

Component 

Arduino Uno X 1

Esp8266 X 1

Relay Module X 1

Some jumper wires

 

 

Working

In Frist part you have to put IP address in the web browser and all the time you turn ON the Arduino its IP Address get changes.

While making it work over Android Application, I gave ESP a static IP which is “192.168.0.107” which is done in coding section (you have assigned static IP Address by checking your router IP Address configuration).

As I am using IP-address for communication it makes things simple and easy.

The communication between the Arduino and mobile phone is based on http protocol (make sure your ESP-module and mobile phone is connected on same network)

Basically, Application is doing all the task that we have to Do in web Browser in First part.

Watch The Part two video you will get all the idea hoe I made an application which do all the stuffs.


App overview:-

I am using Mit app inventer (Click here), Here is the main screen were you can create apllicaton as per your requirnment no need of coding simple pick and place operation

Below is the block section which comes after when you assign the reuried buttons for your project
here you have to creat algorithm using this block code, which make things esay



App Building:-

If you are building simlar kind of project make sure that you assign proper IP addres to you application,
you have frist find out your router ip configuration to assign IP address. Below is the image for that, the higlited part shows the web address which contain IP address it should be change as per your requirnent.
App making video of this project is available in my video (click here) Watch full video to understand



Circuit diagram:-

Make the connection as per this and make sure you esp module as AT frimware in it


I made All the Connection as per Circuit Diagram


Code:-

#include "WiFiEsp.h"
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(3, 2); // RX, TX

#endif
#define Relay_Out 10
char ssid[] = "SSID";            // your network SSID (name)
char pass[] = "PASSWORD";        // your network password
int status = WL_IDLE_STATUS;

int ledStatus = LOW;

WiFiEspServer server(80);

// use a ring buffer to increase speed and reduce memory allocation
RingBuffer buf(8);

void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(Relay_Out,OUTPUT);
  digitalWrite(Relay_Out,HIGH);// initialize digital pin LED_BUILTIN as an output.
  Serial.begin(115200);   // initialize serial for debugging
  Serial1.begin(9600);    // initialize serial for ESP module
  WiFi.init(&Serial1);    // initialize ESP module
  WiFi.config(IPAddress(192,168,0,107));
  // check for the presence of the shield
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue
    while (true);
  }

  // attempt to connect to WiFi network
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network
    status = WiFi.begin(ssid, pass);
  }

  Serial.println("You're connected to the network");
  printWifiStatus();
  
  // start the web server on port 80
  server.begin();
}


void loop()
{
  WiFiEspClient client = server.available();  // listen for incoming clients

  if (client) {                               // if you get a client,
    Serial.println("New client");             // print a message out the serial port
    buf.init();                               // initialize the circular buffer
    while (client.connected()) {              // loop while the client's connected
      if (client.available()) {               // if there's bytes to read from the client,
        char c = client.read();               // read a byte, then
        buf.push(c);                          // push it to the ring buffer

    e
        if (buf.endsWith("\r\n\r\n")) {
          sendHttpResponse(client);
          break;
        }

        // Check to see if the client request was "GET /H" or "GET /L":
        if (buf.endsWith("GET /H")) {
          Serial.println("Turn led ON");
          ledStatus = HIGH;
          digitalWrite(Relay_Out, LOW);   // turn the LED on (HIGH is the voltage level)
        }
        else if (buf.endsWith("GET /L")) {
          Serial.println("Turn led OFF");
          ledStatus = LOW;
          digitalWrite(Relay_Out, HIGH);    // turn the LED off by making the voltage LOW
        }
      }
    }
    
    // close the connection
    client.stop();
    Serial.println("Client disconnected");
  }
}


void sendHttpResponse(WiFiEspClient client)
{
  // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
  // and a content-type so the client knows what's coming, then a blank line:
  client.println("HTTP/1.1 200 OK");
  client.println("Content-type:text/html");
  client.println();
  
  // the content of the HTTP response follows the header:
  client.print("The LED is ");
  client.print(ledStatus);
  client.println("<br>");
  client.println("<br>");
  
  client.println("Click <a href=\"/H\">here</a> turn the LED on<br>");
  client.println("Click <a href=\"/L\">here</a> turn the LED off<br>");
  
  // The HTTP response ends with another blank line:
  client.println();
}

void printWifiStatus()
{
  // print the SSID of the network you're attached to
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print where to go in the browser
  Serial.println();
  Serial.print("To see this page in action, open a browser to http://");
  Serial.println(ip);
  Serial.println();
}


Video

Watch full vide to understand all the things 



Comments