How To Control Home Appliance From Internet Using Arduino and ESP8266

In this article we are showing how you can control your home appliances from anywhere in world using Internet. In our daily life we always forget to switch off Lights, TV, AC, Fan and other appliances and unnecessary we waste electricity and money of course, which is very precious for us.

So we have created a very simple video that you can follow and convert your normal home to Smart Home and you can control from anywhere in world.

Components Required :-

  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

Connection :-

Source Code :-

 

#include "SoftwareSerial.h"

String ssid ="WIFI_NAME";
String password="WIFI_PASSWORD";

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

String server = "www.iotboys.com"; //Your Host 
String uri = "/YOUR_API"; // Your 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 {

Serial.println("Cannot connect to wifi ! Connecting again..."); }
connectWifi();

}
/////////////////////////////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=";

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();

int RED_BULB_ON = response.indexOf("RED_BULB>TRUE")>0?1:0;
int YELLOW_BULB_ON = response.indexOf("YELLOW_BULB>TRUE")>0?1:0;

if(RED_BULB_ON==1)
{
  digitalWrite(RED_BULB, LOW);
}
else
{
  digitalWrite(RED_BULB, HIGH);
}
if(YELLOW_BULB_ON==1)
{
  digitalWrite(YELLOW_BULB, LOW);
}
else
{
  digitalWrite(YELLOW_BULB, HIGH);
}
}
esp.println("AT+CIPCLOSE");

}
}
}

void loop() {
  httpget();
}

You may also like...

17 Responses

  1. An impressive share! I’ve just forwarded this
    onto a colleague who has been doing a little research on this.

    And he in fact bought me lunch simply because I stumbled
    upon it for him… lol. So allow me to reword this…. Thank YOU for the meal!!
    But yeah, thanks for spending time to discuss this subject here on your website.

  2. zikrifuaad says:

    how can i get into the cloud

  3. advocate says:

    I love it when folks cⲟme together and
    ѕhare opіnions. Great website, keep it up!

  4. Rishabh says:

    provide also the web page code to understand the request.

  5. somnath panja says:

    my have no String server = “www.iotboys.com”; //Your Host
    String uri = “/YOUR_API”; // Your URI.. so please give me host server or html code or web page code

    please give me step by step description of this project ,as soon as.

Leave a Reply

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