// 16DTK22F1002 , 16DTK22F1006, 16DTK22F1007
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define MOTION_SENSOR_PIN 2
int motion_state = LOW;
int prev_motion_state = LOW;
// Set the LCD address to 0x27 (or 0x3F depending on your display) for a 20x4 display
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup()
{
Serial.begin(9600);
pinMode(MOTION_SENSOR_PIN, INPUT);
// Initialize the LCD with columns and rows
lcd.begin(20, 4);
lcd.backlight(); // Turn on the backlight
lcd.clear(); // Clear the display
lcd.setCursor(0, 0);
lcd.print("Motion Sensor Ready");
}
void loop() {
prev_motion_state = motion_state;
motion_state = digitalRead(MOTION_SENSOR_PIN);
if (prev_motion_state == LOW && motion_state == HIGH ) {
Serial.println("Motion detected!");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Motion detected!");
}
else if (prev_motion_state == HIGH && motion_state == LOW) {
Serial.println("Motion Stopped!");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Motion Stopped!");
}
}