Control Home Lights Using Facebook Chat Messages

Control Home Lights Using Facebook Chat Messages

Controlling Home Lights using Facebook Chat messages with the help of Arduino, ESP8266 WiFi and a relay board.

  • 4,630 views
  • 3 comments
  • 16 respects

Components and supplies

Apps and online services

About this project

We are showing how you can control your home appliances e.g. TV, fan, refrigerator, lights, etc. through Facebook chat messages with the help of an Arduino Uno and ESP8266 WiFi module.

You just need to send instructions like “Red bulb on," "TV on," or "Room no.1 fan off” in chat and it will control your appliances based this instruction. We are controlling two AC bulbs (red and yellow) for demo purposes, but you can extend functionality in the same manner and can control any appliance in your home. To accomplish this project, we are using Facebook Graph API to communicate with messages and we've created a middle ware in .NET MVC Web API which is responsible for getting the instruction from Facebook Graph API and transferring it to Arduino.

Detail description available on www.iotboys.com

Middle ware .NET code is available on our website www.iotboys.com and also in our Github repository name as "iotboys" .

Visit www.iotboys.com for more attractive projects.

Code

Source CodeC/C++
Source Code for Arduino
#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;
String uri = "/api/FacebookAutomation/ProcessCommand";//YOUR 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();
}

Schematics

Circuit Design
Circuit Design
Control home appliances from anywhere from internet www iotboys com 1024x844 vszgltggwt

Comments

Similar projects you might like

Arduino WhatsApp Messages - Send WhatsApp Messages Using Pi

Project tutorial by Asim Zulfiqar and High Voltages

  • 11,715 views
  • 2 comments
  • 45 respects

Control Arduino Uno Using ESP8266 WiFi Module and Blynk App

Project tutorial by Adithya TG

  • 36,156 views
  • 13 comments
  • 40 respects

Control LED Using Your Voice Command

by Team IoTBoys

  • 27,177 views
  • 4 comments
  • 30 respects
Add projectSign up / Login