/*
PIR sensor tester
*/
int ledPin = 12;
int inputPin = 14;
int pirState = LOW;
int val = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(inputPin, INPUT);
Serial.begin(9600);
}
void loop() {
val = digitalRead(inputPin);
if (val == HIGH) {
digitalWrite(ledPin, HIGH);
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// we only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW);
if (pirState == HIGH) {
// we have just turned of
Serial.println("Motion ended!");
// we only want to print on the output change, not state
pirState = LOW;
}
}
}