Advertisement
safwan092

Project_10622_Arduino_Code

Feb 2nd, 2023
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. #include <Keypad.h>
  2.  
  3. const int ROW_NUM = 4; // four rows
  4. const int COLUMN_NUM = 4; // four columns
  5.  
  6. char keys[ROW_NUM][COLUMN_NUM] = {
  7. { '1', '2', '3', 'A' },
  8. { '4', '5', '6', 'B' },
  9. { '7', '8', '9', 'C' },
  10. { '*', '0', '#', 'D' }
  11. };
  12.  
  13. byte pin_rows[ROW_NUM] = { 9, 8, 7, 6 }; //connect to the row pinouts of the keypad
  14. byte pin_column[COLUMN_NUM] = { 5, 4, 3, 2 }; //connect to the column pinouts of the keypad
  15.  
  16. Keypad keypad = Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM);
  17.  
  18. const String password_1 = "1234"; // change your password here
  19. const String password_2 = "2222"; // change your password here
  20. const String password_3 = "3333"; // change your password here
  21. String input_password;
  22.  
  23. int RELAY = A2;
  24. int sendData = 10;
  25. void setup() {
  26. Serial.begin(115200);
  27. input_password.reserve(32); // maximum input characters is 33, change if needed
  28. pinMode(RELAY, OUTPUT);
  29. pinMode(sendData, OUTPUT);
  30. digitalWrite(sendData,LOW);
  31. }
  32.  
  33. void loop() {
  34. char key = keypad.getKey();
  35. if (key) {
  36. Serial.println(key);
  37. if (key == '*') {
  38. input_password = ""; // reset the input password
  39. } else if (key == '#') {
  40. if (input_password == password_1 || input_password == password_2 || input_password == password_3) {
  41. Serial.println("The password is correct, unlocking the door in 20 seconds");
  42. digitalWrite(sendData,HIGH);
  43. Open();
  44. delay(5000);
  45. digitalWrite(sendData,LOW);
  46. Closee();
  47. } else {
  48. Serial.println("The password is incorrect, try again");
  49. digitalWrite(sendData,LOW);
  50. }
  51.  
  52. input_password = ""; // reset the input password
  53. } else {
  54. input_password += key; // append new character to input password string
  55. }
  56. }
  57. }
  58.  
  59. void Open() {
  60. digitalWrite(RELAY, HIGH);
  61. }
  62. void Closee() {
  63. digitalWrite(RELAY, LOW);
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement