📘 Home Security System ( Blynk IoT Cloud Version )
🎯 Objective of This Lesson
Students will learn:
-
What is Cloud-Based Security Monitoring
-
How ESP32 connects to Blynk Cloud
-
How to create Datastreams
-
How to design Dashboard
-
How to monitor motion from anywhere
🌐 What is Blynk IoT?
Blynk is a cloud IoT platform that allows:
-
Remote device monitoring
-
Real-time alerts
-
Mobile dashboard control
-
Internet-based communication
ESP32 sends motion data to Blynk Cloud.
Mobile app receives it from anywhere.
🧾 Step 1 – Create Blynk Template
1️⃣ Go to: https://blynk.cloud
2️⃣ Login / Sign up
3️⃣ Click Create Template
4️⃣ Choose:
-
Hardware → ESP32
-
Connection Type → WiFi
5️⃣ Save Template
🧾 Step 2 – Create Datastreams
Go to:
Template → Datastreams → New Datastream
Create the following:
| Datastream Name | Virtual Pin | Type |
|---|---|---|
| Motion Status | V0 | String |
| Motion State | V1 | Integer |
Save all.
🧾 Step 3 – Create Device
1️⃣ Go to Devices
2️⃣ Click New Device
3️⃣ From Template
4️⃣ Copy:
-
Template ID
-
Template Name
-
Auth Token
You will paste these into the code.
🧾 Step 4 – Dashboard Setup
Open Web Dashboard or Mobile App.
Add Widgets:
1️⃣ Label → V0 → Motion Status
2️⃣ LED Widget → V1 → Motion State
Configure LED:
-
1 → ON
-
0 → OFF
Dashboard is now ready.
🔌 Hardware Reminder
| PIR Pin | ESP32 Pin |
|---|---|
| VCC | 5V |
| GND | GND |
| OUT | GPIO 27 |
🧾 Complete ESP32 Blynk Code (Copy–Paste Ready)
⚠ Replace WiFi & Blynk credentials before uploading.
#define BLYNK_TEMPLATE_ID "YOUR_TEMPLATE_ID"
#define BLYNK_TEMPLATE_NAME "HomeSecurity"
#define BLYNK_AUTH_TOKEN "YOUR_AUTH_TOKEN"
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#define PIR_PIN 27
char ssid[] = "YOUR_WIFI_NAME";
char pass[] = "YOUR_WIFI_PASSWORD";
BlynkTimer timer;
int motionState = 0;
int lastState = 0;
void sendMotionData() {
motionState = digitalRead(PIR_PIN);
if (motionState == HIGH) {
Blynk.virtualWrite(V0, "⚠ MOTION DETECTED!");
Blynk.virtualWrite(V1, 1);
} else {
Blynk.virtualWrite(V0, "Area Secure");
Blynk.virtualWrite(V1, 0);
}
}
void setup() {
Serial.begin(115200);
pinMode(PIR_PIN, INPUT);
Serial.println("Connecting to Blynk...");
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
Serial.println("Warming up PIR Sensor...");
delay(30000);
Serial.println("System Ready!");
timer.setInterval(2000L, sendMotionData);
}
void loop() {
Blynk.run();
timer.run();
}
🧠 Code Explanation (Step-by-Step)
1️⃣ Blynk Credentials
#define BLYNK_AUTH_TOKEN
These link ESP32 to your cloud project.
Without correct credentials → device will not connect.
2️⃣ Blynk.begin()
Connects ESP32 to:
-
WiFi
-
Blynk Cloud server
3️⃣ Reading PIR Sensor
Returns:
1 → Motion detected
0 → No motion
4️⃣ Sending Data to Cloud
Sends motion status text.
Turns ON LED widget.
5️⃣ Timer Usage
Runs motion check every 2 seconds.
Prevents blocking loop.
📊 Dashboard Example Output
When motion detected:
V0 → ⚠ MOTION DETECTED!
LED → ON
When no motion:
V0 → Area Secure
LED → OFF
🎓 Learning Outcomes
Students now understand:
-
Cloud-based security monitoring
-
Virtual Pins
-
Real-time dashboard control
-
IoT-based home automation
-
Professional deployment structure
🔥 Optional Advanced Upgrade
You can extend this projet by adding:
-
Blynk Notification when motion detected
-
Email alert
-
Event logging
-
Camera integration
-
Multi-room motion system