Yarana Iot Guru
Published © MIT

πŸ’‘ DIY Home Automation: Control LED with Android App

Control LED wirelessly using your Android app and ESP32/ESP8266 β€” the simplest home automation project by YaranaIoT Guru πŸ’‘

BeginnerProtip8 hours17
πŸ’‘ DIY Home Automation: Control LED with Android App

Things used in this project

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

🧠 Arduino Code

C/C++
/*
  DIY Home Automation: Control LED with Android App
  Author: YaranaIoT Guru
*/

#include <WiFi.h>
#include <WebServer.h>

const char* ssid = "YourWiFiName";
const char* password = "YourWiFiPassword";

WebServer server(80);
#define LED_PIN 2

void handle_On() {
  digitalWrite(LED_PIN, HIGH);
  server.send(200, "text/html", "<h1>LED is ON</h1>");
}

void handle_Off() {
  digitalWrite(LED_PIN, LOW);
  server.send(200, "text/html", "<h1>LED is OFF</h1>");
}

void handle_Root() {
  server.send(200, "text/html", "<h1>Welcome to YaranaIoT Guru LED Control</h1>");
}

void setup() {
  Serial.begin(115200);
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, LOW);

  WiFi.begin(ssid, password);
  Serial.print("Connecting to WiFi");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println();
  Serial.print("Connected! IP Address: ");
  Serial.println(WiFi.localIP());

  server.on("/", handle_Root);
  server.on("/on", handle_On);
  server.on("/off", handle_Off);
  server.begin();
  Serial.println("HTTP server started");
}

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

Credits

Yarana Iot Guru
29 projects β€’ 0 followers
Yarana Iot Guru Yarana IoT Guru: Arduino, ESP32, GSM, NodeMCU & more. Projects, Tutorials & App Development. Innovate with us!
Thanks to YaranaIoT Guru.

Comments