0% found this document useful (0 votes)
17 views

Home Automation System Using

The document outlines a home automation system using NodeMCU ESP8266 and the Blynk app, allowing users to remotely control appliances and monitor environmental conditions. It details the components involved, including various sensors for temperature, humidity, gas detection, and water level, as well as the setup process for the Blynk app. Additionally, it includes code snippets for establishing connections, reading sensor data, and controlling appliances through relays.

Uploaded by

Arin Jain
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Home Automation System Using

The document outlines a home automation system using NodeMCU ESP8266 and the Blynk app, allowing users to remotely control appliances and monitor environmental conditions. It details the components involved, including various sensors for temperature, humidity, gas detection, and water level, as well as the setup process for the Blynk app. Additionally, it includes code snippets for establishing connections, reading sensor data, and controlling appliances through relays.

Uploaded by

Arin Jain
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Home Automation System Using

NodeMCU and Blynk


Introduction
Home automation is the use of technology to remotely monitor
and control household systems such as water level,
humidity, temperature, and appliances.
Objective
This project demonstrates how to build a home automation
system
using NodeMCU ESP8266 and the Blynk app.

It enables users to:


• Remotely control home appliances (lights, fans, etc.)
• Monitor temperature, humidity, gas leaks, and water
levels
Working of Components

ESP8266 (WiFi Module)


Connects the system to WiFi and communicates with the Blynk cloud
for remote monitoring and control.
DHT11 Sensor (Temperature & Humidity)
Measures temperature and humidity and sends data to the Blynk app
for real-time monitoring.

MQ-2 Gas Sensor


Detects gas leaks (LPG, CO, smoke) and triggers an alarm (Buzzer) if the
level is high.
Sends a warning notification to the Blynk app.

Ultrasonic Sensor (Water Level Monitoring)


Measures the distance of water level in a tank using sound waves.
Displays the level on the Blynk app.

Relays (Appliance Control)


Relay 1 & Relay 2 control electrical appliances (lights, fans, etc.).
Users can turn devices ON/OFF remotely via Blynk.

Buzzer
Alerts users in case of a gas leak or other critical conditions.
Blynk App Setup

1. Install Blynk App or or use chrome

• Sign up and create a new project (Name: Home Automation).

• Select ESP8266, choose WiFi, and get the Auth Token.

2. Add Widgets

• Gas Sensor (MQ-2) → Gauge (V1)

• Temperature & Humidity (DHT11) → Label/Gauge (V2, V3)

• Water Level (Ultrasonic Sensor) → Gauge/Graph (V4)


• Relay 1 & 2 (Control Appliances) → Button (V5, V6)

3. Connect to ESP8266

• paste Auth Token into the Arduino code.

• Upload the code and connect to Blynk Cloud.

4. Test & Monitor

• View sensor data and control relays remotely.

This setup enables remote control & monitoring of your home


automation system!

Code
#define BLYNK_TEMPLATE_ID "TMPL3CfFycCJF“

#define BLYNK_TEMPLATE_NAME "HOME AUTOMATION" #include <Wire.h>

#include <ESP8266WiFi.h>

#include <BlynkSimpleEsp8266.h>

#include <DHT.h>

char auth[] = "5DHMFX91htIzoZ-69h3wXxKmy-uWRcBi"; char ssid[] = "TEENA";

char pass[] = "teen@008";

DHT dht(D3, DHT11);

BlynkTimer timer;

#define Buzzer D0

#define MQ2 A0

#define trig D4

#define echo D5
#define relay1 D7

#define relay2 D8

void checkConnection()

{ if (WiFi.status() != WL_CONNECTED)

Serial.println("WiFi Disconnected! Reconnecting...");

WiFi.begin(ssid, pass);

int timeout = 0;

while (WiFi.status() != WL_CONNECTED && timeout < 20)

delay(500);

Serial.print("."); timeout++;

if (WiFi.status() == WL_CONNECTED)

Serial.println("\nWiFi Reconnected to: " + String(WiFi.SSID()));

else { Serial.println("\nWiFi Connection Failed!");

if (!Blynk.connected())

Serial.println("Blynk Disconnected! Reconnecting...");

Blynk.connect();

}
}

void setup() { Serial.begin(9600);

pinMode(Buzzer, OUTPUT);

pinMode(trig, OUTPUT);

pinMode(echo, INPUT);

pinMode(relay1, OUTPUT);

pinMode(relay2, OUTPUT);

digitalWrite(relay1, HIGH);

digitalWrite(relay2, HIGH);

Serial.println("Connecting to WiFi...");

WiFi.begin(ssid, pass);

while (WiFi.status() != WL_CONNECTED)

delay(500);

Serial.print(".");

Serial.println("\nConnected to WiFi: " + String(WiFi.SSID()));

Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);

dht.begin();

timer.setInterval(1000L, gassensor);

timer.setInterval(1000L, DHT11sensor);

timer.setInterval(1000L, ultrasonic);

void gassensor()
{

int value = analogRead(MQ2);

Serial.print("Gas Sensor Value: ");

Serial.println(value);

value = map(value, 0, 1024, 0, 100);

if (value > 25)

{ Blynk.logEvent("gas_leak", "Warning! Gas leak detected");

digitalWrite(Buzzer, HIGH);

else

digitalWrite(Buzzer, LOW);

Blynk.virtualWrite(V1, value);

void DHT11sensor()

float h = dht.readHumidity();

float t = dht.readTemperature();

if (isnan(h) || isnan(t))

Serial.println("Failed to read from DHT sensor!");

return;

Blynk.virtualWrite(V2, t);

Blynk.virtualWrite(V3, h);
Serial.print("Temperature: ");

Serial.print(t);

Serial.print(" C, Humidity: ");

Serial.print(h);

Serial.println(" %");

void ultrasonic()

digitalWrite(trig, LOW);

delayMicroseconds(4);

digitalWrite(trig, HIGH);

delayMicroseconds(10);

digitalWrite(trig, LOW);

long t = pulseIn(echo, HIGH);

long cm = t / 29 / 2;

Blynk.virtualWrite(V4, cm); Serial.print("Water Level Distance: ");

Serial.print(cm);

Serial.println(" cm");

BLYNK_WRITE(V5)

int state = param.asInt();

digitalWrite(relay1, state ? LOW : HIGH);

Serial.print("Relay 1 State: "); Serial.println(state);

}
BLYNK_WRITE(V6)

int state = param.asInt();

digitalWrite(relay2, state ? LOW : HIGH);

Serial.print("Relay 2 State: ");

Serial.println(state);

void loop()

checkConnection();

Blynk.run();

timer.run();

QUESTIONS
1. NodeMCU and Blynk Integration

Q: Explain how the NodeMCU ESP8266 connects to the Blynk cloud. What steps are required to ensure
stable WiFi connectivity and remote control functionality?

 Write the code to establish a connection between NodeMCU and Blynk, ensuring reconnection
in case of a WiFi failure.

2. Sensor Functionality and Applications

Q: The MQ-2 sensor is used for gas detection. Describe how it works, how the system alerts users in case
of a gas leak, and how the Blynk app handles notifications.

 Write the code to read gas levels from the MQ-2 sensor and send alerts to the Blynk app when
dangerous levels are detected.

3. Water Level Monitoring

Q: How does the HC-SR04 ultrasonic sensor measure water level? Explain its working principle and how
the system displays the data in the Blynk app.
 Write the code to measure the water level using the HC-SR04 sensor and update the Blynk app
with real-time readings.

4. Relay Module for Appliance Control

Q: What role do relay modules play in this home automation system? Explain how they are controlled
through the Blynk app and how the system ensures user safety.

 Write the code to control a relay module using the Blynk app, allowing users to turn an
appliance ON/OFF remotely.

5. Blynk vs. ThingSpeak

Q: Compare Blynk and ThingSpeak in terms of functionality. In which scenarios would it be more
beneficial to use ThingSpeak instead of Blynk?

 Write the code to send sensor data (e.g., temperature, gas levels) to ThingSpeak for data logging
and visualization.

You might also like