Home Automation System using Arduino and IoT
Project Overview
This Home Automation System allows users to control household appliances remotely using a smartphone or computer. The system utilizes Arduino, ESP8266 (Wi-Fi module), and Relays to switch electrical devices on and off. Users can send commands through a mobile app or web interface, making their home smarter and more convenient.
1. Components Required
Component | Quantity | Description |
---|---|---|
Arduino Uno/Nano | 1 | Microcontroller Board |
ESP8266 Wi-Fi Module | 1 | For Internet connectivity |
4-Channel Relay Module | 1 | To control high voltage appliances |
Bulb/Fan/LED (AC devices) | 2-3 | Electrical appliances for demonstration |
Jumper Wires | As needed | For connections |
Breadboard | 1 | For prototyping |
5V Power Supply | 1 | To power ESP8266 and relays |
2. Circuit Diagram and Pin Connections
2.1 ESP8266 to Arduino
ESP8266 Pin | Arduino Pin |
---|---|
VCC | 3.3V |
GND | GND |
TX | RX (via voltage divider) |
RX | TX |
CH_PD | 3.3V |
2.2 Relay Module to Arduino
Relay Pin | Arduino Pin |
---|---|
VCC | 5V |
GND | GND |
IN1 | D4 |
IN2 | D5 |
IN3 | D6 |
IN4 | D7 |
The relays are connected to electrical appliances, allowing the system to control them remotely.
3. Code Implementation
This Arduino code establishes Wi-Fi communication using the ESP8266 module and controls appliances via HTTP requests.
Required Libraries
ESP8266WiFi.h
WiFiClient.h
ESP8266WebServer.h
Install these libraries via Arduino Library Manager.
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
const char* ssid = "Your_SSID";
const char* password = "Your_PASSWORD";
ESP8266WebServer server(80);
#define RELAY_1 D4
#define RELAY_2 D5
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to Wi-Fi...");
}
Serial.println("Connected to Wi-Fi");
Serial.println(WiFi.localIP());
pinMode(RELAY_1, OUTPUT);
pinMode(RELAY_2, OUTPUT);
digitalWrite(RELAY_1, HIGH);
digitalWrite(RELAY_2, HIGH);
server.on("/relay1/on", []() {
digitalWrite(RELAY_1, LOW);
server.send(200, "text/plain", "Relay 1 ON");
});
server.on("/relay1/off", []() {
digitalWrite(RELAY_1, HIGH);
server.send(200, "text/plain", "Relay 1 OFF");
});
server.on("/relay2/on", []() {
digitalWrite(RELAY_2, LOW);
server.send(200, "text/plain", "Relay 2 ON");
});
server.on("/relay2/off", []() {
digitalWrite(RELAY_2, HIGH);
server.send(200, "text/plain", "Relay 2 OFF");
});
server.begin();
Serial.println("Server started");
}
void loop() {
server.handleClient();
}
4. Working Explanation
- The ESP8266 connects to Wi-Fi using the provided credentials.
- It hosts a local web server to accept HTTP requests.
- When the user sends a command (e.g.,
http://192.168.1.X/relay1/on
), the server activates the respective relay, turning on the connected appliance. - The user can control multiple appliances from any web browser or mobile app.
Projects for Beginners and Enthusiasts
Click here: https://iotbyhvm.ooo/10-exciting-arduino-projects-for-beginners-and-enthusiasts/