22bcs10114 - Ayush Gupta Iot
22bcs10114 - Ayush Gupta Iot
Experiment 4
Student Name: Ayush Gupta UID: 22BCS10114
Branch: BE-CSE Section/Group: 625/A
Semester: Sixth Date of Performance: 17-02-2025
Subject Name: Foundation of Cloud IOT Edge ML Lab (22CSP-367)
1. Aim: Build a security system with any sensor and alerts using Blynk..
2. Objective: To design and implement a security system using sensors (e.g., PIR motion sensor,
magnetic door sensor, or ultrasonic sensor) and integrate it with the Blynk platform to send
real-time alerts.
3. Requirements:
a) PIR Motion Sensor (HC-SR501)
b) ESP8266/NodeMCU (or any Wi-Fi-enabled microcontroller)
c) Buzzer/LED (for local alerts, optional)
d) Blynk App (installed on your smartphone)
e) Breadboard and jumper wires
f) Ultrasonic Sensor (HC-SR04)
4. Procedure:
1. Connect the Hardware: PIR Sensor Pinout:
• VCC: Connect to 3.3V or 5V (depending on the sensor model).
• GND: Connect to GND.
• OUT: Connect to a digital pin on ESP8266 (e.g., D5).
Wiring Diagram:
• PIR VCC → NodeMCU 3.3V
• PIR GND → NodeMCU GND
• PIR OUT → NodeMCU D5
• Buzzer/LED (optional) → D2
2. Set Up Blynk:
• Download and install the Blynk app
• Create a new project and select ESP8266 as the device.
• Note down the Auth Token sent to your email.
• Add a Notification Widget in the app for alerts.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
/**void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, Muthu");
Serial.println("Let's Go!!");
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}
PIR output connectted in ESP pin 13
DHT22 output connectted in ESP pin 14
LED(assume LED as Buzzer) output connectted in ESP pin 15
Button output connectted in ESP pin 18
**/
#define BLYNK_TEMPLATE_ID "TMPL6WDk9AYgF"
#define BLYNK_TEMPLATE_NAME "EXP 4"
#define BLYNK_AUTH_TOKEN "2wjduz1ULBIH1fqyZxsbEgskupZX4swl"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
#include <BlynkSimpleEsp32.h>
#include <DHT.h>
// Blynk Authentication Token
char auth[] = BLYNK_AUTH_TOKEN;
// WiFi credentials
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
// DHT sensor settings
#define DHTPIN 14
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
// PIR sensor pin
const int pirPin = 13;
// Buzzer pin
const int buzzerPin = 15;
// LED pin
const int ledPin = 16;
const int ledPin1 = 17;
// Button pin
const int buttonPin = 18;
// Variables
int pirState = LOW;
int buttonState = LOW;
int oldValue = HIGH;
void setup() {
// Initialize serial communication
Serial.begin(115200);
// Initialize Blynk
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
}
//Read button (door/window sensor)
buttonState = digitalRead(buttonPin);
/**
if (buttonState == LOW) {
digitalWrite(ledPin1, HIGH);
delay(1000);
Blynk.virtualWrite(V3, 1); // Trigger virtual pin for door/window notification
} else {
Blynk.virtualWrite(V3, 0); // Reset virtual pin for door/window notification
}
**/
int newValue = buttonState;
// Check if the value was changed,
// by comparing it with the previous value.
if(newValue != oldValue)
{
if(newValue == LOW)
{
digitalWrite(ledPin1, HIGH);
//delay(2000);
Blynk.virtualWrite(V3, 1); // Trigger virtual pin for door/window notification
delay(2000);
Serial.println("The button is pressed.");
}
else
{
digitalWrite(ledPin1, LOW);
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
6. Output:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
7. Conclusion:
The combination of ESP32 and Blynk showcases how modern microcontrollers and IoT platforms
can improve security. The system efficiently detects motion using a PIR sensor and monitors
ambient light to differentiate between day and night. Alerts and notifications are managed via the
Blynk app, enabling real-time updates and remote access. ESP32 ensures smooth communication
and processing, while the PIR sensor accurately detects movement, triggering alarms as needed. The
light sensor enhances intrusion detection in low-light settings, making the system more responsive
and effective.