IoT-Based Smart Home Automation with ESP32 and Blynk
IoT-Based Smart Home Automation with ESP32 and Blynk file DarutQEHFKiv9dYD9UhaEL

IoT-Based Smart Home Automation with ESP32 and Blynk

1. Introduction

This project builds a Wi-Fi-enabled home automation system using the ESP32 microcontroller and Blynk IoT platform. With this setup, users can remotely control household appliances like lights, fans, and AC units via a smartphone and monitor temperature and humidity in real time.

Applications:

  • Smart Home Automation – Control home appliances from anywhere.
  • Energy Management – Optimize electricity usage.
  • Security Enhancements – Add motion sensors for smart security.

2. Learning Objectives

  • Understand ESP32’s Wi-Fi capabilities in IoT applications.
  • Interface relays, sensors, and mobile apps for remote control.
  • Use Blynk IoT for a seamless smartphone control system.
  • Log and display real-time sensor data using ESP32.

3. Required Components

Hardware:

  • ESP32 Development Board
  • 4-Channel Relay Module
  • DHT11/DHT22 Sensor (for temperature and humidity)
  • LEDs & 220Ω Resistors
  • 5V Power Adapter
  • Breadboard & Jumper Wires
  • AC Bulbs or Fans (for testing)

Software:

  • Arduino IDE
  • Blynk IoT App (Android/iOS)
  • Blynk Library & ESP32 Board Package

4. Circuit Wiring

Connections:

  1. Relay Module:
    • Connect VCC to ESP32’s 5V.
    • Connect GND to ESP32 GND.
    • Relay control pins (IN1, IN2, IN3, IN4) to GPIO 23, 22, 21, 19.
  2. DHT11 Sensor:
    • VCC to 3.3V of ESP32.
    • GND to ESP32 GND.
    • Data pin to GPIO 18 (with a 10kΩ pull-up resistor).
  3. Status LED (Optional):
    • Anode (+) to GPIO 2.
    • Cathode (-) to GND via a 220Ω resistor.

5. Setting Up Blynk

  1. Install the Blynk App on your smartphone.
  2. Create a New Project, selecting ESP32 as the board.
  3. Copy the Auth Token from the app.
  4. Add Control Buttons for each relay and assign them to virtual pins (V1, V2, etc.).
  5. Add a Label for displaying temperature and humidity data.

6. Programming the ESP32

#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#include <DHT.h>

#define DHTPIN 18
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

// Blynk Auth & Wi-Fi Credentials
char auth[] = "Your_Blynk_Auth_Token";
char ssid[] = "Your_WiFi_SSID";
char pass[] = "Your_WiFi_Password";

// Define Relay GPIOs
#define RELAY_1 23
#define RELAY_2 22
#define RELAY_3 21
#define RELAY_4 19

void setup() {
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
dht.begin();

pinMode(RELAY_1, OUTPUT);
pinMode(RELAY_2, OUTPUT);
pinMode(RELAY_3, OUTPUT);
pinMode(RELAY_4, OUTPUT);

digitalWrite(RELAY_1, HIGH);
digitalWrite(RELAY_2, HIGH);
digitalWrite(RELAY_3, HIGH);
digitalWrite(RELAY_4, HIGH);
}

// Virtual Button Callbacks
BLYNK_WRITE(V1) { digitalWrite(RELAY_1, param.asInt()); }
BLYNK_WRITE(V2) { digitalWrite(RELAY_2, param.asInt()); }
BLYNK_WRITE(V3) { digitalWrite(RELAY_3, param.asInt()); }
BLYNK_WRITE(V4) { digitalWrite(RELAY_4, param.asInt()); }

void loop() {
Blynk.run();
float temp = dht.readTemperature();
float hum = dht.readHumidity();

if (!isnan(temp) && !isnan(hum)) {
Blynk.virtualWrite(V5, temp);
Blynk.virtualWrite(V6, hum);
}
delay(2000);
}

7. Testing & Debugging

Testing:

  1. Upload the code to the ESP32 using Arduino IDE.
  2. Open Serial Monitor (115200 baud) to check Wi-Fi connection.
  3. Open the Blynk App, press virtual buttons, and check if the relays toggle.
  4. Observe real-time temperature and humidity readings in the app.

Troubleshooting:

  • Wi-Fi Not Connecting? Verify SSID/password.
  • Relays Not Switching? Check wiring and 5V power.
  • Sensor Not Reading? Ensure pull-up resistor (10kΩ) is connected.
  • Blynk App Not Updating? Recheck the Auth Token and internet connection.

8. Project Enhancements

  • Add MQTT Support: Use MQTT for cloud connectivity instead of Blynk.
  • Voice Control: Integrate Google Assistant or Alexa via IFTTT.
  • Energy Monitoring: Use an ACS712 Current Sensor for real-time power tracking.
  • Security Add-ons: Include PIR motion sensors for smart security.

9. Conclusion

This ESP32-based smart home automation system enables remote appliance control and sensor monitoring using the Blynk IoT platform. The project provides a strong foundation for expanding into more advanced IoT applications like AI-driven automation, voice control, and cloud integration. 🚀