/*
MSJ Researchers World
Date - 18th NOV 2024
Mentor - Mr. Siranjeevi M
Contact - 7373771991
*/
// Define pins for PIR sensor and buzzer
const int pirPin = 3; // PIR sensor output pin
const int buzzerPin = 5; // Buzzer pin
// Variable to store PIR sensor state
int pirState = LOW;
void setup() {
// Initialize pins
pinMode(pirPin, INPUT);
pinMode(buzzerPin, OUTPUT);
// Initialize serial communication (optional for debugging)
Serial.begin(9600);
}
void loop() {
// Read PIR sensor state
pirState = digitalRead(pirPin);
// If motion is detected
if (pirState == HIGH) {
Serial.println("Motion detected!");
// Generate emergency alert tone
for (int i = 0; i < 3; i++) { // Repeat the alert tone 3 times
tone(buzzerPin, 1000, 500); // Frequency: 1000 Hz, Duration: 500ms
delay(600); // Wait slightly longer than tone duration
tone(buzzerPin, 1500, 500); // Frequency: 1500 Hz, Duration: 500ms
delay(600); // Wait slightly longer than tone duration
}
delay(1000); // Cooldown period before sensing again
} else {
// No motion detected
Serial.println("No motion");
noTone(buzzerPin); // Ensure the buzzer is off
}
delay(100); // Short delay for sensor stabilization
}