#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Initialize the LCD at address 0x27 with 16 columns and 2 rows
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int sensorPin = 2; // IR Sensor connected to digital pin 2
int personCount = 0;
bool sensorState = false;
bool lastSensorState = false;
void setup() {
lcd.init(); // Initialize LCD
lcd.backlight(); // Turn on LCD backlight
pinMode(sensorPin, INPUT); // Set sensor pin as input
lcd.setCursor(0, 0);
lcd.print(" Entry Counter @ CLASS ROOM ");
delay(2000);
lcd.clear();
}
void loop() {
sensorState = digitalRead(sensorPin);
// Check for rising edge: No detection to detection
if (sensorState == LOW && lastSensorState == HIGH) {
personCount++;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Person Entered");
lcd.setCursor(0, 1);
lcd.print("Total: ");
lcd.print(personCount);
delay(500); // Debounce delay
}
// Update last state
lastSensorState = sensorState;
}