#include <LiquidCrystal.h>
// Initialize the LCD library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
int pirSensorPin = 2; // PIR sensor pin
int pirState = LOW; // Start assuming no motion detected
int val = 0; // Variable for reading the PIR status
void setup() {
pinMode(pirSensorPin, INPUT); // Set the PIR sensor pin as an input
lcd.begin(16, 2); // Set up the LCD's number of columns and rows
lcd.print("No motion"); // Print initial message
}
void loop() {
val = digitalRead(pirSensorPin); // Read input value from the PIR sensor
if (val == HIGH) { // Check if the PIR sensor's output is HIGH
if (pirState == LOW) {
// We have just turned on
lcd.clear();
lcd.print("Motion detected!"); // Print message
pirState = HIGH;
}
} else {
if (pirState == HIGH) {
// We have just turned off
lcd.clear();
lcd.print("No motion"); // Print message
pirState = LOW;
}
}
}