#define BLYNK_TEMPLATE_ID "TMPL6dUfFQIFc"
#define BLYNK_TEMPLATE_NAME "Quickstart Template"
#define BLYNK_AUTH_TOKEN "zW6lw0CTYb8KbbegweuWR0cEeQhORF4k"
//ຫລັງຈາກ ລັນແລ້ວ ແມ່ນໄຫ້ກົດປູ່ມ * ກ່ອນແລ້ວຄ່ອຍກົດ Password
//password man ABC
#include <Keypad.h>
#include <Servo.h>
#include <LiquidCrystal_I2C.h> // Library for LCD
#define ROW_NUM 4 // four rows
#define COLUMN_NUM 4 // four columns
#define SERVO_PIN A0 // // the Arduino pin, which connects to the servo motor
Servo servo; // servo motor
LiquidCrystal_I2C lcd(0x27, 16, 2);
int buzzerPin = 13;
int led_red = 11;
int led_green = 12;
char keys[ROW_NUM][COLUMN_NUM] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte pin_rows[ROW_NUM] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
const String password_1 = "ABC"; // change your password here
// change your password here
String input_password;
int angle = 0; // the current angle of servo motor
unsigned long lastTime;
void setup() {
Serial.begin(9600);
input_password.reserve(32); // maximum password size is 32, change if needed
lcd.init(); //initialize the lcd
lcd.backlight();
servo.attach(SERVO_PIN);
servo.write(0); // rotate servo motor to 0°
lastTime = millis();
pinMode(buzzerPin, OUTPUT);
pinMode(led_red, OUTPUT);
pinMode(led_green, OUTPUT);
}
void loop() {
char key = keypad.getKey();
if (key) {
Serial.println(key);
if (key == '*') {
lcd.print("Enter Pass:....");
input_password = ""; // reset the input password
} else if (key == '#') {
if (input_password == password_1 ) {
lcd.clear();
lcd.print("Correct");
Serial.println("The password is correct, rotating Servo Motor to 90°");
angle = 90;
servo.write(angle);
lastTime = millis();
digitalWrite(buzzerPin , HIGH);
tone(buzzerPin, 500, 500);
digitalWrite(led_green, HIGH);
digitalWrite(led_red, LOW);
delay(5000);
lcd.clear();
digitalWrite(led_green,LOW);
lcd.print("Enter Pass:....");
} else {
lcd.clear();
lcd.print("Pass is wrong");
digitalWrite(led_red, HIGH);
digitalWrite(led_green,LOW);
digitalWrite(buzzerPin ,HIGH);
tone(buzzerPin, 100, 5000);
delay(5000);
digitalWrite(led_red,LOW);
lcd.clear();
lcd.print("Enter Pass:....");
}
input_password = ""; // reset the input password
} else {
input_password += key; // append new character to input password string
}
}
if (angle == 90 && (millis() - lastTime) > 5000) { // 5 seconds
angle = 0;
servo.write(angle);
Serial.println("Rotating Servo Motor to 0°");
}
}