#include <ESP32Servo.h>
Servo myServo;
const int servoPin = 13;
const int buttonPin = 14;
const int systemLed = 25;
const int correctLed = 26;
const int wrongLed = 27;
String correctPassword = "1234";
String enteredPassword = "";
void setup() {
Serial.begin(9600);
pinMode(buttonPin, INPUT_PULLUP);
pinMode(systemLed, OUTPUT);
pinMode(correctLed, OUTPUT);
pinMode(wrongLed, OUTPUT);
myServo.attach(servoPin);
myServo.write(0);
}
void loop() {
if (digitalRead(buttonPin) == LOW) {
digitalWrite(systemLed, HIGH);
Serial.println("System ON - Enter Password");
if (Serial.available()) {
char c = Serial.read();
if (c == '\n') {
if (enteredPassword == correctPassword) {
Serial.println("Access Granted");
digitalWrite(correctLed, HIGH);
digitalWrite(wrongLed, LOW);
myServo.write(90);
delay(10000);
myServo.write(0);
digitalWrite(correctLed, LOW);
}
else {
Serial.println("Wrong Password");
digitalWrite(wrongLed, HIGH);
digitalWrite(correctLed, LOW);
delay(2000);
digitalWrite(wrongLed, LOW);
}
enteredPassword = "";
Serial.println("Enter Password:");
}
else if (c != '\r') {
enteredPassword += c;
}
}
}
else {
digitalWrite(systemLed, LOW);
}
}