// House Security Alarm using Arduino, Motion Sensor, and Buzzer //
// Christine Alo - BETCPET 3C NS //
// Finals Exams CPET11-M //
const int motionSensorPin = 3;
const int buzzerPin = 4;
const int stopButtonPin = 2;
void setup() {
pinMode(motionSensorPin, INPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(stopButtonPin, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
int motionValue = digitalRead(motionSensorPin);
if (motionValue == HIGH) {
activateAlarm();
}
// Check if the stop button is pressed
if (digitalRead(stopButtonPin) == LOW) {
stopAlarm(); // Stop the alarm
}
}
void activateAlarm() {
Serial.println("Motion detected! Alarm activated.");
digitalWrite(buzzerPin, HIGH); // Turn on the buzzer
}
void stopAlarm() {
Serial.println("Alarm stopped.");
digitalWrite(buzzerPin, LOW); // Turn off the buzzer
delay(1000); // Add a delay to avoid multiple button presses
}