/*
PIR sensor tester
*/
#include <LiquidCrystal_I2C.h>
#define LCD_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_ROWS 2
LiquidCrystal_I2C lcd(LCD_ADDR,LCD_COLUMNS,LCD_ROWS);
int ledPin = 13; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for PIR sensor) // we start, assuming no motion detected
int val1 = 0;
int val2 = 0 ; // variable for reading the pin status
int inputPinOut = 1;
int count = 0;
int pirState = LOW;
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
lcd.begin(16,2);
lcd.init();
lcd.backlight();
lcd.setCursor(5,0);
Serial.begin(9600);
}
void loop() {
lcd.print(count);
val1 = digitalRead(inputPin); // read input value
val2 = digitalRead(inputPinOut);
if (val1 == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH);
count = count + 1; // turn LED ON
}
else if (val2 == HIGH) {
count = count - 1;
}
if (val2 == HIGH && count == 0) {
digitalWrite(ledPin, LOW); // turn LED OFF
}
}