loader
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:-

Control Home Appliances From Anywhere From Internet 1

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

38 Comments

  1. Ahmad Sayeed

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

      1. IoT Boys

        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

  2. ingrid

    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

    1. IoT Boys

      Hello ingrid,
      Could you please write your comment in English language.
      Sorry to say that we couldn’t understand your comment.

      Best Regards,
      IoTBoys

      1. Mitendra Arya

        Hi IoT Boys.
        Its nice to see you doing great work.

        Can u please get in deep touch with this idea?

  3. Sridarshan Dasi

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

    1. IoT Boys

      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

  4. Rahul

    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

  5. Hima Bindu Gorantla

    Is any of you have completed this project?Will you please send us the document related to this project or related links

  6. khaled fawzy

    can you please make a video to describing the instruction to upload the middleware application to any web host and how to configure and link with Facebook graph API
    regards

  7. H VABEIZAWZI BEIA

    it was a good tutorial,but the connection was easy, you guys must include a video of creating the most critical part which is that kind of API… Im totally lost.. if you could provide that part of linking most of us will be more helpful and we can have the knowledge and more interesting in these field.Thank You

  8. danish

    please you must include the confirmation message from esp so i’ll get to know that esp switch the led sucessfully.

  9. danish

    please include confirmation message from esp side so that i come to know that wether my actutator is off or not.

  10. Osi

    Boys,
    Don’t you want to upgrade the code using ESP8266 board, like Wemos D1 R2 & Mini. And your first video has been removed.

    Cheers,
    Osi

Leave a Reply

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