#define pirPin A2
int calibrationTime = 30;
long unsigned int lowIn;
long unsigned int pause = 50;
boolean lockLow = true;
boolean takeLowTime;
int PIRValue = 0;
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
void setup() {
lcd.init();
Serial.begin(9600);
pinMode(pirPin, INPUT);
}
void loop() {
lcd.backlight();
if(digitalRead(pirPin) == HIGH) {
if(lockLow) {
PIRValue = 1;
lockLow = false;
Serial.println("Motion detected.");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Motion detected");
delay(1);
}
takeLowTime = true;
}
if(digitalRead(pirPin) == LOW) {
if(takeLowTime){
lowIn = millis();takeLowTime = false;
}
if(!lockLow && millis() - lowIn > pause) {
PIRValue = 0;
lockLow = true;
Serial.println("Motion ended.");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Motion ended.");
delay(1);
}
}
}