safwan092

Untitled

Mar 8th, 2022
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. #include <Servo.h>
  2. #include <Keypad.h>
  3.  
  4. int signalPin = A0;
  5.  
  6. #define Password_Length 8
  7.  
  8. char Data[Password_Length];
  9. char Master[Password_Length] = "123A456";
  10. byte data_count = 0, master_count = 0;
  11. bool Pass_is_good;
  12. char customKey;
  13.  
  14. const byte ROWS = 4;
  15. const byte COLS = 4;
  16.  
  17. char hexaKeys[ROWS][COLS] = {
  18. {'1', '2', '3', 'A'},
  19. {'4', '5', '6', 'B'},
  20. {'7', '8', '9', 'C'},
  21. {'*', '0', '#', 'D'}
  22. };
  23.  
  24. byte rowPins[ROWS] = {9, 8, 7, 6};
  25. byte colPins[COLS] = {5, 4, 3, 2};
  26.  
  27. Servo myServo;
  28. Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
  29.  
  30. void setup() {
  31. pinMode(signalPin, OUTPUT);
  32. digitalWrite(signalPin, LOW);
  33. myServo.attach(2);
  34. myServo.write(0);
  35. delay(5000);
  36. }
  37.  
  38. void loop() {
  39. customKey = customKeypad.getKey();
  40.  
  41. if (customKey) {
  42. Data[data_count] = customKey;
  43. Serial.print(Data[data_count]);
  44. data_count++;
  45. }
  46. if (data_count == Password_Length - 1) {
  47. lcd.clear();
  48. if (!strcmp(Data, Master)) {
  49. Serial.println();
  50. // Open Door: Servo + Solienoid
  51. openDoorAction();
  52. }
  53. else {
  54. Serial.println();
  55. // Close Door: Servo + Solienoid
  56. closeDoorAction();
  57. }
  58. }
  59.  
  60. }// end of LOOP
  61.  
  62.  
  63. void clearData1() {
  64. while (data_count != 0) {
  65. Data[data_count--] = 0;
  66. }
  67. return;
  68. }
  69.  
  70. void openDoorAction() {
  71. digitalWrite(signalPin, HIGH);
  72. myServo.write(90);
  73. delay(5000);
  74. digitalWrite(signalPin, LOW);
  75. myServo.write(0);
  76. clearData1();
  77. }
  78.  
  79. void closeDoorAction() {
  80. myServo.write(0);
  81. delay(1000);
  82. clearData1();
  83. lcd.clear();
  84. }
Advertisement
Add Comment
Please, Sign In to add comment