Home Automation Using Facebook Chat And Arduino ESP8266 WiFi Module

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

You may also like...

30 Responses

  1. Ahmad Sayeed says:

    Something that I have never heard. I know we can operate this trough intrent but never though about Facebook chat.

  2. Anish G says:

    Can you guys please share the middleware .NET code.
    Thanks

  3. Aakash says:

    Great, adding a camera will be more attractive. Can you please do that?

  4. Adnan says:

    Hi, could you please let me know where to download your middleware .net?

    Thanks

  5. Habib says:

    Hi,
    Pls tell me how to connect fb my mobile fb account how to connect

    • Habib says:

      Middle wire what? My fb email address. Whare u write http://www.iotboys.com here writing my fb email address right

      • IoT Boys IoT Boys says:

        Middle Ware means there is a middle tier which is handling the request and response from Arduino to Facebook chat, so you must have a Windows Web Server(IIS), where you can host out middleware code and update the config with your Facebook pageID and access_token.

        Best Regards,
        IoTBoys

  6. IoT Boys IoT Boys says:

    Hi Habib,
    You need to first create a Facebook page then you can connect with that Facebook page using Facebook Graph API.
    We have used a middle ware developed in .NET to connect with Facebook Graph API .
    Let us know if you have still doubt.

    Best Regards,
    IoTBoys
    https://facebook.com/iotboys
    https://twitter.com/iotboys

  7. ingrid says:

    bonjour le demande si c’est seulement sur le meme seveur on peux envoyer les messages ou si on peux envoyer par notre propre compte facebook

  8. ingrid says:

    I asked how to install the midllware, I downloaded files already,

  9. ingrid says:

    ok how can we modify your code and the herberger or we can host it directly?

  10. Sridarshan Dasi says:

    Hello Sir Please help me…How to Connect our Facebook Page with Facebook Graph API

  11. Habib says:

    hi friend pls sent me graph API LINK and how to do access token

    • IoT Boys IoT Boys says:

      Hi Habib,
      We are preparing the details steps for this project in format of PPT, will update the same link so keep visited.
      Most probbaly will update by tomorrow EOD.

      Best Regards,
      IoTBoys

  12. Mihir says:

    hello are u done with the detail step for the project?

    please share it

  13. Rahul says:

    It’s really incredible something different from other it’s made me more innovative in it sector. I also want to control same home application with voice command. But component should be same what you ppl used in above. So if u have anything like that please share with me…. Thank s

  14. Teja says:

    where did I have to upload this middle ware?

  15. Thanks for the excellent manual

Leave a Reply

Your email address will not be published. Required fields are marked *