const int pir1Pin = 2;
const int pir2Pin = 3;
const int ledPin = 4;
const int buzzerPin = 5;
int motionDetected1 = 0;
int motionDetected2 = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin (9600);
pinMode (pir1Pin, INPUT);
pinMode (pir2Pin, INPUT);
pinMode (ledPin, OUTPUT);
pinMode (buzzerPin, OUTPUT);
Serial.println("Hello World");
}
void loop() {
// put your main code here, to run repeatedly:
motionDetected1 = digitalRead(pir1Pin);
motionDetected2 = digitalRead(pir2Pin);
Serial.println(motionDetected1);
if (motionDetected1 == HIGH) {
//Turn on the LED
digitalWrite (ledPin, HIGH);
Serial.println ("PIR Sensor 1: Motion Detected! LED ON");
delay (500);
} else {
// Turn off the LED
digitalWrite (ledPin, LOW);
}
if (motionDetected2 == HIGH) {
//Trigger the buzzer
digitalWrite (buzzerPin, HIGH);
Serial.println ("PIR Sensor 2: Motion Detected! Buzzer ON");
delay (500);
} else {
// Turn off the LED
digitalWrite (buzzerPin, LOW);
}
delay (100);
}