// Define Pin Allocations
const int pirSensorPin = 7; // PIR motion output pin
const int greenLedPin = 2; // Secure indicator
const int redLedPin = 3; // Alarm indicator
const int buzzerPin = 4; // Audible siren
// Variable to track motion state
int motionStatus = LOW;
void setup() {
// Setup output devices
pinMode(greenLedPin, OUTPUT);
pinMode(redLedPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
// Setup input device
pinMode(pirSensorPin, INPUT);
// Open communication to Serial Monitor
Serial.begin(9600);
Serial.println("--- PIR Motion Security System Active ---");
}
void loop() {
// Read the digital state of the PIR sensor
motionStatus = digitalRead(pirSensorPin);
if (motionStatus == HIGH) {
// MOTION DETECTED!
digitalWrite(greenLedPin, LOW); // Kill secure light
digitalWrite(redLedPin, HIGH); // Trigger alert light
// Play an alternating security siren (800Hz to 1200Hz)
tone(buzzerPin, 1200, 150);
delay(150);
tone(buzzerPin, 800, 150);
Serial.println("[INTRUSION ALERT] Motion detected in the secured zone!");
}
else {
// SYSTEM SECURE
digitalWrite(greenLedPin, HIGH); // Keep secure light alive
digitalWrite(redLedPin, LOW); // Ensure alert light is dead
noTone(buzzerPin); // Silence the siren
}
// Small delay to allow simulation processing
delay(100);
}