#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#define BUZZER_PIN 4
#define LED_PIN 5
LiquidCrystal_I2C lcd(0x3F, 16, 2);
// Keypad Configuration
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {13, 12, 14, 27};
byte colPins[COLS] = {26, 25, 33, 32};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
// Simulated RFID Codes (Predefined)
String registered_IDs[] = {"123A", "456B", "789C"};
String entered_ID = "";
void setup() {
Serial.begin(115200);
lcd.init();
lcd.backlight();
pinMode(BUZZER_PIN, OUTPUT);
pinMode(LED_PIN, OUTPUT);
lcd.setCursor(0, 0);
lcd.print("Smart Attendance");
delay(2000);
lcd.clear();
}
void loop() {
char key = keypad.getKey();
if (key) {
Serial.print("Key Pressed: ");
Serial.println(key);
if (key == '#') { // Enter button
checkAttendance();
entered_ID = "";
}
else if (key == '*') { // Reset input
entered_ID = "";
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter ID:");
}
else {
entered_ID += key;
lcd.setCursor(0, 1);
lcd.print(entered_ID);
}
}
}
void checkAttendance() {
bool isRegistered = false;
for (int i = 0; i < 3; i++) {
if (entered_ID == registered_IDs[i]) {
isRegistered = true;
break;
}
}
lcd.clear();
if (isRegistered) {
lcd.setCursor(0, 0);
lcd.print("Attendance Marked!");
Serial.println("Attendance Marked!");
digitalWrite(LED_PIN, HIGH);
digitalWrite(BUZZER_PIN, HIGH);
delay(1000);
digitalWrite(BUZZER_PIN, LOW);
digitalWrite(LED_PIN, LOW);
}
else {
lcd.setCursor(0, 0);
lcd.print("Invalid ID!");
Serial.println("Invalid ID!");
for (int i = 0; i < 3; i++) {
digitalWrite(BUZZER_PIN, HIGH);
delay(200);
digitalWrite(BUZZER_PIN, LOW);
delay(200);
}
}
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter ID:");
}