/*
PIR sensor tester
*/
#include <LiquidCrystal.h>
int ledPin = 13; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for PIR sensor)
int pirState = digitalRead(2); // we start, assuming no motion detected
int val = 0;
LiquidCrystal lcd(13,12,11,10,9,8); // variable for reading the pin status
void setup() {
lcd.begin(16,2);
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
Serial.begin(9600);
}
void loop() {
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH);
lcd.setCursor(0,0); // turn LED ON
if (pirState == LOW) {
// we have just turned on
lcd.setCursor(0,1);
lcd.print("Motion Detected");
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
delay(1500);
}
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirState == HIGH) {
lcd.setCursor(0,1);
lcd.print("No Motion");
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
delay(1500);
lcd.clear();
}
}
}