#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int ledPin = 13;
const int tamperPin = 8;
const int maxAttempts = 3;
String fullName = "Vishnu Nair";
String regNum = "2347131";
int incorrectAttempts = 0;
bool tampered = false;
String enteredCode = "";
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(tamperPin, INPUT_PULLUP);
lcd.begin(16, 2);
lcd.clear();
Serial.begin(9600);
Serial.println("Enter Security Code:");
displayPattern();
}
void loop() {
if (Serial.available() > 0) {
enteredCode = Serial.readStringUntil('\n');
enteredCode.trim();
checkSecurityCode(enteredCode);
}
if (digitalRead(tamperPin) == LOW) {
tampered = true;
}
if (incorrectAttempts >= maxAttempts || tampered) {
blinkLED();
}
}
void displayPattern() {
String initials = String(fullName[0]) + "." + String(fullName[fullName.indexOf(' ') + 1]) + ".";
String lastFourDigits = regNum.substring(4, 8);
lcd.setCursor(0, 0);
lcd.print(initials + " " + lastFourDigits);
lcd.setCursor(0, 1);
for (int i = 0; i < 4; i++) {
lcd.print((int)fullName[i]);
lcd.print(" ");
}
}
void checkSecurityCode(String enteredCode) {
String correctCode = regNum;
if (enteredCode != correctCode) {
incorrectAttempts++;
Serial.println("Incorrect Code. Attempts left: " + String(maxAttempts - incorrectAttempts));
if (incorrectAttempts >= maxAttempts) {
Serial.println("Too many incorrect attempts. Alert triggered!");
}
} else {
Serial.println("Access Granted!");
incorrectAttempts = 0;
}
}
void blinkLED() {
digitalWrite(ledPin, HIGH);
delay(200);
digitalWrite(ledPin, LOW);
delay(200);
}