Arduino ESP8266 IoT IoT Projects Videos

Home Automation Using Facebook Chat And Arduino ESP8266 WiFi Module

Voice Control Home Automation System Using Arduino and HC-05

Going further to explain Home Automation Using Facebook Chat And Arduino ESP8266 WiFi Module. After reading and watching this video you will be able to control your home appliances e.g. TV, Fan, Refrigerator, Lights etc. from Facebook chat message with the help of Arduino Uno and ESP8266 WiFi Module.

You just need to send instructions like “RED BULB ON, TV ON, Room No-1 Fan Off” in chat and it will control your appliences based on your instruction. To accomplish this project we are using Facebook Graph API to communicate with Facebook Page messages and also created a middle-ware in .NET Web API technology which is responsible for getting the instruction from Facebook Graph API.

Home Automation Using Facebook Chat – Part – I

Home Automation Using Facebook Chat – Part – II

What Is The Role of Middle-Ware Application :-

As name suggest Middle-Ware, the role of this is to be a middle things, So basically this is a RESTful Web API application that has been written in .NET framework that keeps communicate with Facebook Graph API. So whenever any command comes to the Facebook page e.g. “RED BULB OFF“, “YELLOW BULB ON” etc. this RESTful API code will have that command, because from Arduino we are calling this middle-ware each second.

10 Things Required for Home Automation Using Facebook Chat And Arduino ESP8266 WiFi Module:-

  1. 1 x Arduino uno board
  2. 1 x USB cable
  3. 1 x ESP8266 WiFi Module
  4. 1 x Relay Board
  5. 1 x Jumper wire (Male to Male)
  6. 9 x Jumper wire (Male to Female)
  7. 1 x Breadboard
  8. 1 x Yellow Bulb
  9. 1 x Red Bulb
  10. Middleware Written in .NET Web API (REST Service) Click Here To Download

Connection Diagram:-

Source Code for Home Automation Using Facebook Chat And Arduino ESP8266 WiFi Module :-

#include "SoftwareSerial.h"

String ssid = "YOUR_SSID";
String password = "YOUR_WIFI_PASSWORD";

SoftwareSerial esp(3, 2);// RX, TX

String server = "www.iotboys.com"//YOUR_MIDDLE_WARE Server Address;
String uri = "/api/FacebookAutomation/ProcessCommand";//MIDDLE WARE URI

int RED_BULB = 5;
int YELLOW_BULB = 6;

void setup() {

  pinMode(RED_BULB, OUTPUT);
  pinMode(YELLOW_BULB, OUTPUT);

  digitalWrite(RED_BULB, HIGH);
  digitalWrite(YELLOW_BULB, HIGH);
  esp.begin(9600);

  Serial.begin(9600);

  connectWifi();

  httpget();

  delay(1000);

}
void connectWifi() {

  String cmd = "AT+CWJAP=\"" + ssid + "\",\"" + password + "\"";

  esp.println(cmd);

  delay(4000);

  if (esp.find("OK")) {

    Serial.println("Connected!");

  }

  else {

    connectWifi();

    Serial.println("Cannot connect to wifi");
  }

}
/////////////////////////////GET METHOD///////////////////////////////

void httpget() {
  esp.println("AT+CIPSTART=\"TCP\",\"" + server + "\",80");//start a TCP connection.

  if ( esp.find("OK")) {

    Serial.println("TCP connection ready");

  } delay(1000);

  String getRequest =
    "GET " + uri + " HTTP/1.0\r\n" +
    "Host: " + server + "\r\n" +
    "Accept: *" + "/" + "*\r\n" +
    "Content-Type: application/json\r\n" +
    "\r\n";

  String sendCmd = "AT+CIPSEND=";//determine the number of caracters to be sent.

  esp.print(sendCmd);

  esp.println(getRequest.length() );

  delay(500);

  if (esp.find(">")) {
    Serial.println("Sending..");
    esp.print(getRequest);

    if ( esp.find("SEND OK")) {

      Serial.println("Packet sent");

      while (esp.available()) {

        String response = esp.readString();

        Serial.println(response);
       
        if (response.indexOf("RED BULB ON") > 0)
        {
          digitalWrite(RED_BULB, LOW);
        }
        else if (response.indexOf("RED BULB OFF") > 0)
        {
          digitalWrite(RED_BULB, HIGH);
        }
        else if (response.indexOf("YELLOW BULB ON") > 0)
        {
          digitalWrite(YELLOW_BULB, LOW);
        }
        else if (response.indexOf("YELLOW BULB OFF") > 0)
        {
          digitalWrite(YELLOW_BULB, HIGH);
        }
        else if (response.indexOf("ALL ON") > 0)
        {
          digitalWrite(RED_BULB, LOW);
          digitalWrite(YELLOW_BULB, LOW);
        }
        else if (response.indexOf("ALL OFF") > 0)
        {
          digitalWrite(RED_BULB, HIGH);
          digitalWrite(YELLOW_BULB, HIGH);
        }

      }
      // close the connection
      esp.println("AT+CIPCLOSE");

    }
  }
}

void loop() {
  httpget();
}
Home Automation Using Facebook Chat And Arduino ESP8266 WiFi Module

How To Control Home Appliance From Internet Using Arduino and ESP8266

Voice Control Home Automation System Using Arduino and HC-05

About the author

IoT Boys

IoT Boys

30 Comments

Click here to post a comment

Meet Our Team

Rajeev Ranjan Founder IoTBoys
Founder IoTBoys
Shambhoo kumar
Founder IoTBoys

Subscribe Us