/*
PIR sensor tester
*/
int ledPinPir1 = 13; // choose the pin for the LED
int ledPinPir2 = 5; // choose the pin for the LED
int inputPinPir1 = 2; // choose the input pin (for PIR sensor)
int inputPinPir2 = 4; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val1 = 0; // variable for reading the pin status
int val2 = 0; // variable for reading the pin status
void setup() {
pinMode(ledPinPir1, OUTPUT); // declare LED as output
pinMode(ledPinPir2, OUTPUT); // declare LED as output
pinMode(inputPinPir1, INPUT); // declare sensor as input
pinMode(inputPinPir2, INPUT); // declare sensor as input
Serial.begin(9600);
}
void loop() {
val1 = digitalRead(inputPinPir1); // read input value
if (val1 == HIGH) { // check if the input is HIGH
digitalWrite(ledPinPir1, HIGH); // turn LED ON
Serial.print("Motion detected in Pir1! | ");
tone(7, 1000, 500);
}
else{
digitalWrite(ledPinPir1, LOW); // turn LED OFF
Serial.print("No motion detected in Pir1! | ");
}
val2 = digitalRead(inputPinPir2); // read input value
if (val2 == HIGH) { // check if the input is HIGH
digitalWrite(ledPinPir2, HIGH); // turn LED ON
Serial.println("Motion detected in Pir2!");
tone(7, 500, 500);
}
else{
digitalWrite(ledPinPir2, LOW); // turn LED OFF
Serial.println("No motion detected in Pir2!");
}
delay(1000);
}