IoTBoysRajiv SharmaShambhoo kumar
Published

Control Home Appliance From Internet Using Arduino and WiFi

Control home appliances from anywhere in world using Internet. Make your home smart with Arduino and ESP8266 WiFi Module.

AdvancedProtip12 hours86,901
Control Home Appliance From Internet Using Arduino and WiFi

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
ESP8266 ESP-01
Espressif ESP8266 ESP-01
×1
Relay (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Two AC Bulbs(Red,Yellow)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
REST API

Story

Read more

Schematics

Circuit Design

Circuit Design

Code

Source Code

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

Credits

IoTBoys

IoTBoys

9 projects • 115 followers
Watch, Learn and Built IoT projects | DIY IoT Projects | IoT Projects for College Student.
Rajiv Sharma

Rajiv Sharma

17 projects • 71 followers
Having more than 10 years of experience in IoT and software technology. Founded IoTBoys to share knowledge with IoT enthusiasts.
Shambhoo kumar

Shambhoo kumar

4 projects • 43 followers

Comments