// كود البوابة مع الصوت
#include <Keypad.h>
#define RELAY_PIN 21 // ESP32 pin GIOP14 connected to the IN pin of relay تم التعديل
#define ROW_NUM 4 // four rows
#define COLUMN_NUM 4 // four columns
#define BUZZ_PINN 16 //تم الانشاء
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] = {13, 12, 14, 27}; // GIOP19, GIOP18, GIOP5, GIOP17 connect to the row pins تم التعديل
byte pin_column[COLUMN_NUM] = {26, 25, 33, 32}; // GIOP16, GIOP4, GIOP0, GIOP2 connect to the column pins تم التعديل
Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
const String password_1 = "4"; // change your password here
const String password_2 = "5"; // change your password here
const String password_3 = "9"; // change your password here
String input_password;
void setup() {
Serial.begin(9600);
input_password.reserve(32); // maximum input characters is 32
pinMode(RELAY_PINN, OUTPUT);
digitalWrite(RELAY_PINN, LOW); //تم التعديل
// lock the door
pinMode(BUZZ_PIN, OUTPUT); //تم الانشاء
digitalWrite(BUZZ_PIN, LOW); //تم الانشاء
}
void loop() {
char key = keypad.getKey();
if (key) {
Serial.println(key);
if (key == '*') {
input_password = ""; // reset the input password
} else if (key == '#') {
if (input_password == password_1 || input_password == password_2 || input_password == password_3) {
Serial.println("Valid Password => unlock the door");
//................................. تم التعديل
digitalWrite(BUZZ_PIN , HIGH);
delay(200);
digitalWrite(BUZZ_PIN , LOW);
delay(200);
digitalWrite(BUZZ_PIN , HIGH);
delay(200);
digitalWrite(BUZZ_PIN , LOW);
delay(200);
digitalWrite(BUZZ_PIN , HIGH);
delay(200);
digitalWrite(BUZZ_PIN , LOW);
delay(300);
//................................ الى هنا تم التعديل
digitalWrite(RELAY_PINN, HIGH); // unlock the door for 20 seconds تم التعديل
delay(50);
digitalWrite(RELAY_PINN, LOW); // lock the door تم التعديل
} else {
digitalWrite(BUZZ_PIN, HIGH);
delay(500);
digitalWrite(BUZZ_PIN , LOW);
Serial.println("Invalid Password => Try again");
}
input_password = ""; // reset the input password
} else {
input_password += key; // append new character to input password string
}
}
}