#include <LiquidCrystal_I2C.h>
#define PIR_SENSOR 10
LiquidCrystal_I2C lcd(0x27, 20, 4);
int pirState = LOW;
bool mot_flag = true;
bool nomot_flag = true;
void lcd_clear() {
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print(" ");
}
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
pinMode(PIR_SENSOR, INPUT);
}
void loop() {
int current_pir = digitalRead(PIR_SENSOR);
if (current_pir == HIGH)
{
mot_flag = true;
if(nomot_flag == true)
{
lcd_clear();
nomot_flag = false;
}
lcd.setCursor(0, 0);
lcd.print("Motion detected!");
}
else
{
nomot_flag = true;
if(mot_flag == true)
{
lcd_clear();
mot_flag = false;
}
lcd.setCursor(0, 0);
lcd.print("No motion");
}
}