#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>
#include <Servo.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_LINES 2
#define BuzzerPin 10
#define ServoPin 11
#define LedPin 12
#define RelayPin 13
Servo myservo;
int pos = 0;
char password[6];
char initial_password[6];
int i=0;
int relay_pin = 10;
char key_pressed=0;
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
uint8_t colPins[COLS] = { 5, 4, 3, 2 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 9, 8, 7, 6 }; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
int pass1, pass2;
void setup() {
Serial.begin(9600);
pinMode(BuzzerPin, OUTPUT);
pinMode(LedPin, OUTPUT);
pinMode(ServoPin, OUTPUT);
pinMode(RelayPin, OUTPUT);
myservo.attach(11);
digitalWrite(LedPin, HIGH);
lcd.init();
lcd.backlight();
// Print something
lcd.setCursor(1, 0);
lcd.print("Input Password");
delay(1000);
lcd.setCursor(0, 1);
InputPassword();
}
void loop() {
String passw = String(EEPROM.read(0))+String(EEPROM.read(1))+String(EEPROM.read(2));
key_pressed = keypad.getKey();
if (key_pressed)
{
password[i++]=key_pressed;
lcd.print(key_pressed);
}
if(i==6)
{
delay(200);
for(int j=0;j<6;j++)
initial_password[j]=passw[j];
if((strncmp(password, initial_password,4)== 0))
{
Servo1();
lcd.clear();
lcd.print("Password Benar");
delay(1000);
lcd.setCursor(0,1);
lcd.clear();
lcd.print("Enter Password:");
lcd.setCursor(0,1);
i=0;
}
else
{
digitalWrite(BuzzerPin, HIGH);
digitalWrite(RelayPin, HIGH);
lcd.clear();
lcd.print("Password Salah!");
lcd.setCursor(0,1);
delay(1000);
lcd.clear();
lcd.print("Enter Password");
lcd.setCursor(0,1);
i=0;
}
}
}
void InputPassword(){
//password : 201088
EEPROM.write(0, 20);
EEPROM.write(1, 10);
EEPROM.write(2, 88);
}
void Servo1(){
for (pos = 90; pos <= 180; pos += 1) {
myservo.write(pos);
delay(15);
}
}