// Importing required libraries
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <BlynkSimpleEsp32.h>
// Define pin connections
const int pirPin = 12; // PIR sensor pin connected to ESP32 pin 12
const int ledPin = 13; // LED pin connected to ESP32 pin 13
const int buzzerPin = 14; // Buzzer pin connected to ESP32 pin 14
// Blynk credentials
char auth[] = "SCPv4_sBbX81bTg04Fnb4RAS1dc1HmLB"; // Blynk Authentication Token
char templateId[] = "TMPL3cGrK5WeW"; // Blynk Template ID
char deviceName[] = "Motion Activated Security Camera"; // Blynk Device Name
// Initialize the LCD display (16x2) with I2C address 0x27
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
// Initialize the serial communication for debugging purposes
Serial.begin(115200);
// Set up pins as input/output
pinMode(pirPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
// Initialize the LCD display
lcd.init();
lcd.backlight();
lcd.clear();
// Display a welcome message
lcd.setCursor(0, 0);
lcd.print("Welcome!");
delay(2000);
lcd.clear();
// Initialize Blynk with your credentials
Blynk.begin(auth, "Sardardham", " ", templateId, deviceName);
}
void loop() {
// Read the PIR sensor state (HIGH if motion detected)
int pirState = digitalRead(pirPin);
if (pirState == HIGH) {
// Motion detected: activate the LED and buzzer
digitalWrite(ledPin, HIGH);
digitalWrite(buzzerPin, HIGH);
// Display the message on the LCD display
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Motion Detected!");
// Optional: print a message to the serial monitor
Serial.println("Motion Detected!");
// Send notification to Blynk app
Blynk.notify("Alert: Motion Detected!");
} else {
// No motion detected: deactivate the LED and buzzer
digitalWrite(ledPin, LOW);
digitalWrite(buzzerPin, LOW);
// Display "Motion Not Detected" message on the LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Motion Not Detected");
}
// Run Blynk in the loop
Blynk.run();
}