Sikkandar Sulaiman
Published © GPL3+

Begin Home Automation: Only ESP8266

Switch your home appliances through WiFi from your phone/pc by connecting to ESP8266 hotspot as an intranetwork.

BeginnerShowcase (no instructions)1 hour5,743
Begin Home Automation: Only ESP8266

Things used in this project

Hardware components

ESP8266 ESP-01
Espressif ESP8266 ESP-01
×1
Jumper wires (generic)
Jumper wires (generic)
×4
RobotGeek Relay
RobotGeek Relay
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

ESP8266 and relay - Schematic

A schematic about how to wire this project.

Code

ESP access point & server

Arduino
A code which makes your ESP8266 as an Access point, and as a web server serving a web page with a button and displays the status of the bulb connected to the relay, pressing the button toggles the gpio2 of ESP8266 thus by controlling the relay.
#include <ESP8266WiFi.h> 
#include <ESP8266WebServer.h>

const char *ssid = "Any name you wish";
const char *pass = "your-secret-password";

ESP8266WebServer server(80);
String html = "<!DOCTYPE html><html><head>"\
"<meta name='viewport' content='width=device-width, initial-scale=1\'"\
"</head><body>"\
"<form method='GET' action='gpio2'>"\
"<button >Light</button><hr>"\
"</form>"\
"<h2>Light is ON</h2>"\
"</body></html>";

void start() {
  if(digitalRead(2)) {
    html.replace("ON", "OFF");
    server.send(200, "text/html", html);
  }
  else {
    html.replace("OFF", "ON");
    server.send(200, "text/html", html);
  }
}

void gpio2() {
  digitalWrite(2,!digitalRead(2));
  start();
}

void setup() {
  pinMode(2,1);
  digitalWrite(2,0);
  WiFi.softAPConfig({192,168,4,1},{192,168,4,1},{255,255,255,0});
  WiFi.softAP(ssid, pass);
  server.on("/", start);
  server.on("/gpio2", gpio2);
  server.begin();
}

void loop() {
  server.handleClient();
}

Credits

Sikkandar Sulaiman

Sikkandar Sulaiman

5 projects • 24 followers
Engineering student actively working with IoT, Image Processing and Robotics.

Comments