ArduinoIoT HardwaresTutorials/DIY

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

ComponentQuantityDescription
Arduino Uno/Nano1Microcontroller Board
ESP8266 Wi-Fi Module1For Internet connectivity
4-Channel Relay Module1To control high voltage appliances
Bulb/Fan/LED (AC devices)2-3Electrical appliances for demonstration
Jumper WiresAs neededFor connections
Breadboard1For prototyping
5V Power Supply1To power ESP8266 and relays

2. Circuit Diagram and Pin Connections

2.1 ESP8266 to Arduino

ESP8266 PinArduino Pin
VCC3.3V
GNDGND
TXRX (via voltage divider)
RXTX
CH_PD3.3V

2.2 Relay Module to Arduino

Relay PinArduino Pin
VCC5V
GNDGND
IN1D4
IN2D5
IN3D6
IN4D7

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

  1. ESP8266WiFi.h
  2. WiFiClient.h
  3. ESP8266WebServer.h

Install these libraries via Arduino Library Manager.

C
#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

  1. The ESP8266 connects to Wi-Fi using the provided credentials.
  2. It hosts a local web server to accept HTTP requests.
  3. 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.
  4. 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/

Harshvardhan Mishra

Hi, I'm Harshvardhan Mishra. Tech enthusiast and IT professional with a B.Tech in IT, PG Diploma in IoT from CDAC, and 6 years of industry experience. Founder of HVM Smart Solutions, blending technology for real-world solutions. As a passionate technical author, I simplify complex concepts for diverse audiences. Let's connect and explore the tech world together! If you want to help support me on my journey, consider sharing my articles, or Buy me a Coffee! Thank you for reading my blog! Happy learning! Linkedin

Leave a Reply

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