Advertisement
safwan092

Untitled

Feb 28th, 2022
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Wire.h>
  3. #include <Servo.h>
  4. #include <Keypad.h>
  5. #include <MFRC522.h>
  6. #include <LiquidCrystal_I2C.h>
  7.  
  8. #define SS_PIN 10
  9. #define RST_PIN 9
  10. int signalPin = A0;
  11.  
  12. #define Password_Length 8
  13.  
  14. char Data[Password_Length];
  15. char Master[Password_Length] = "123A456";
  16. byte data_count = 0, master_count = 0;
  17. bool Pass_is_good;
  18. char customKey;
  19.  
  20. const byte ROWS = 4;
  21. const byte COLS = 4;
  22.  
  23. char hexaKeys[ROWS][COLS] = {
  24. {'1', '2', '3', 'A'},
  25. {'4', '5', '6', 'B'},
  26. {'7', '8', '9', 'C'},
  27. {'*', '0', '#', 'D'}
  28. };
  29.  
  30. byte rowPins[ROWS] = {A3, 8, 7, 6};
  31. byte colPins[COLS] = {5, 4, 3, A2};
  32.  
  33. Servo myServo;
  34. MFRC522 mfrc522(SS_PIN, RST_PIN);
  35. LiquidCrystal_I2C lcd(0x27, 16, 2);
  36. Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
  37.  
  38. void setup() {
  39. Serial.begin(9600);
  40. SPI.begin();
  41. mfrc522.PCD_Init();
  42. pinMode(signalPin, OUTPUT);
  43. digitalWrite(signalPin, LOW);
  44. lcd.init();
  45. lcd.init();
  46. lcd.backlight();
  47. lcd.setCursor(0, 0);
  48. lcd.print("Starting");
  49. myServo.attach(2);
  50. myServo.write(0);
  51. delay(5000);
  52. Serial.println("Scanning Card...");
  53. Serial.println();
  54. }
  55.  
  56. void loop() {
  57. lcd.setCursor(0, 0);
  58. lcd.print("Enter Password:");
  59. customKey = customKeypad.getKey();
  60.  
  61. if (customKey) {
  62. Data[data_count] = customKey;
  63. Serial.print(Data[data_count]);
  64. lcd.setCursor(data_count, 1);
  65. lcd.print(Data[data_count]);
  66. data_count++;
  67. }
  68. if (data_count == Password_Length - 1) {
  69. lcd.clear();
  70. if (!strcmp(Data, Master)) {
  71. Serial.println();
  72. // Open Door: Servo + Solienoid
  73. openDoorAction();
  74. }
  75. else {
  76. Serial.println();
  77. // Close Door: Servo + Solienoid
  78. closeDoorAction();
  79. }
  80. lcd.clear();
  81. }
  82.  
  83. if ( ! mfrc522.PICC_IsNewCardPresent()) {
  84. return;
  85. }
  86.  
  87. if ( ! mfrc522.PICC_ReadCardSerial() ) {
  88. return;
  89. }
  90.  
  91. String content = "";
  92. byte letter;
  93. for (byte i = 0; i < mfrc522.uid.size; i++) {
  94. Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
  95. Serial.print(mfrc522.uid.uidByte[i], HEX);
  96. content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
  97. content.concat(String(mfrc522.uid.uidByte[i], HEX));
  98. }
  99. Serial.println();
  100. content.toUpperCase();
  101.  
  102. if (content.substring(1) == "14 65 FE 2B" || content.substring(1) == "39 B1 28 C2")
  103. {
  104. // Open Door: Servo + Solienoid
  105. openDoorAction();
  106. }
  107. else
  108. {
  109. // Close Door: Servo + Solienoid
  110. closeDoorAction();
  111. }
  112.  
  113. }// end of LOOP
  114.  
  115.  
  116. void clearData1() {
  117. while (data_count != 0) {
  118. Data[data_count--] = 0;
  119. }
  120. return;
  121. }
  122.  
  123. void openDoorAction() {
  124. Serial.println("Access Granted");
  125. lcd.setCursor(0, 1);
  126. lcd.print("Access Granted");
  127. digitalWrite(signalPin, HIGH);
  128. myServo.write(90);
  129. delay(5000);
  130. digitalWrite(signalPin, LOW);
  131. myServo.write(0);
  132. clearData1();
  133. lcd.clear();
  134. }
  135.  
  136. void closeDoorAction() {
  137. Serial.println("Access Denied");
  138. lcd.setCursor(0, 1);
  139. lcd.print("Access Denied");
  140. myServo.write(0);
  141. delay(1000);
  142. clearData1();
  143. lcd.clear();
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement