loader
How To Control Home Appliances 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 :-

Control Home Appliances From Anywhere From Internet 1

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

62 Comments

  1. Alex

    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.

    1. Saddar Uddin Memon

      Salam, bro my esp8266 can not connect to my system and no any AT command work what I do plz give your ideas. Thnkx

    2. Saddar Uddin Memon

      Salam, bro my esp8266 can not connect to my system and no any AT command work what I do plz give your ideas. Thnkx

    1. IoT Boys

      Hi Zikifuaad,

      You can go with AWS or Azure if you have knowledge of API development, we have used Web API in this project.
      Other than that you can use MQTT also.

    1. IoT Boys

      Hello Rishabh,
      Thanks for reaching us.
      That page is only having HTML and Angular code where we are calling a web API that we have developed in ASP.NET Web API.
      Let us know if you still need this.

      Best Regards,
      IoTBoys

          1. Vijay

            Can you forward me the mail web page code sent iot boys for home automation using arduino and esp8266..

          2. micheal

            Hi
            I want to tryit
            if you can send me HTML code
            and I have a question
            what do you mean about:
            String uri = “/YOUR_API”; // Your URI

            I wait your reply
            my mail
            eng.mikelseha@gmail.com

          1. Andrey

            Can you forward me the mail web page code sent iot boys for home automation using arduino and esp8266

          2. Prabath

            Hello, I am also trying to develop the web page for this project. Could you please send me the code for the web page too.

  2. somnath panja

    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.

  3. deepak yadav m

    i have connected and programmed the arduino but how to use the switch button through your website,please reply fast

  4. Alireza

    Thanks for your tutorial.Could you please send me the html file? I dont know anything about html programming or API.

    1. IoT Boys

      Hi Alireza,
      To accomplish this project better to have knowledge about Web API and HTML because this is just a demo project lot of other things you need to do apart from this video.
      You must have a web server enabled IIS so that you can host our middleware code there and can make request. Once you are able to host the application let us know will provide the html source code.

      Best Regards,
      IoTBoys

      1. Alireza

        I got a free host with iis server from somee.com and learned how to upload files on the server.Could you please send me the html source code?

  5. Danish

    Hello ! CAN you tell me how to connect ESP8266 WiFi Module with internet, I have connected each and every thing according to your diagram and have uploaded the same code to my arduino uno that you have provided, please help me out in this. Please

  6. Sunbun

    This design is spectacular! You obviously know how to keep a reader amused. Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Excellent job. I really loved what you had to say, and more than that, how you presented it. Too cool!

  7. Aditya

    Nice Project Really Impressive. Can I please get the server side code? It would be a great help.

  8. Vijay

    Please provide also the web page code to understand the request as soon as possible. Can I add one more device in that

  9. Gracia Ortenzio

    I really can’t believe how great this site is. Keep up the good work. I’m going to tell all my friends about this place.

  10. Shery Sick

    That sure is one pretty site you have there. Can I ask you a very simple question? What kind of fertilizer do you use to make it grow so wonderfully?

  11. Vishnu

    in the video at last you have directly gone to the site of controlling. can you please explain how to open the site and its address

  12. Rachana Bobade

    which app u have used for controlling the system
    plzz could u mail the datails or help em with that

  13. Kelly Chevalier

    Hey there! I’ve been reading your website for some time
    now and finally got the bravery to go ahead and give you a
    shout out from Lubbock Tx! Just wanted to say keep up the good job!

  14. Prakash Sanyasi

    Great Job IoTBoys!!
    I am very thankful for your tutorial. We are doing similar project for a module in college. But i am stuck in between not knowing how to write API in back-end as I am beginner. We will be thankful if you could share your API or make tutorial for write API for similar project.
    THANK YOU

  15. رمزيات حب

    Hello, yes this article is in fact good and I have learned lot of things from it on the topic of blogging.
    thanks.

  16. michelle

    Hello, I found this helpful. We are going to create smart home lighting controlled by Android Smartphone using WiFi. Is this project okay to do with android application? because I’ve watched the video you controlled the lights using laptop.. do you have any tutorial, for controlling by using android smartphone or android app?

  17. Michelle

    Can you please kindly reply on my message soon as you read it 🙂 We’re planning to buy arduino device soon, because we only have 1 and half week for our sembreak.. I just needed the list of hardware components for now we’re writing documentation for our capstone. Thank You IoT Boys ^_^ btw, I already have use HTML, JAVA, PHP language.. what was the language will be used in this project ? because I am new to this kind of project.

  18. phani krishna

    hello sir ,
    i need the html and api code for the following project in arduino beacause we need to develop the apk frontend and some more brief about the project. thanks in advance

  19. Abbas

    Do i have to configure my ESP8266 also or i just have to put the code in arduino??
    secondly how can i conncet to a link like you have show in your video a website from where you switch on and off the bulbs

Leave a Reply

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