Advertisement
Guest User

FINISHED FINAL

a guest
Feb 15th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. #include <LiquidCrystal_I2C.h>
  2. #include <SPI.h>
  3. #include <MFRC522.h>
  4. #include <Servo.h>
  5. #include <Keypad.h>
  6. #define SS_PIN 10
  7. #define RST_PIN 9
  8. constexpr uint8_t greenLed = 16;
  9. constexpr uint8_t redLed = 15;
  10. MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
  11. Servo Tahm;
  12. LiquidCrystal_I2C screen(0x3f,16,2);
  13. int i=0;
  14. char initial_password [4]={'4','4','2','1'};
  15. int key_pressed = 0;
  16. char password[4];
  17. const byte ROWS = 4; //four rows
  18. const byte COLS = 4; //four columns
  19. char keys[ROWS][COLS] = {
  20. {'1','2','3',},
  21. {'4','5','6',},
  22. {'7','8','9',},
  23. {'*','0','#',}
  24. };
  25. byte rowPins[ROWS] = { 8,7, 6, 5}; //connect to the row pinouts of the keypad
  26. byte colPins[COLS] = { 4, 3, 2,}; //connect to the column pinouts of the keypad
  27. Keypad keypad_key = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
  28. //Keypad keypad_key = Keypad( makeKeymap(keys), row_pins, column_pins, rows, columns);
  29.  
  30.  
  31. void setup()
  32. {
  33. screen.begin();
  34. screen.setBacklight((uint8_t)1);
  35. Serial.begin(9600); // Initiate a serial communication
  36. SPI.begin(); // Initiate SPI bus
  37. mfrc522.PCD_Init(); // Initiate MFRC522
  38. Serial.println("Searching for a card.");
  39. Serial.println();
  40. Tahm.attach (14);
  41. Tahm.write (0);
  42. msg();
  43. }
  44. void msg() {
  45. screen.clear();
  46. screen.print(" Scan");
  47. screen.setCursor (0,1);
  48. screen.print (" a card..");
  49. }
  50. void loop()
  51. {
  52. // Look for new cards
  53. if ( ! mfrc522.PICC_IsNewCardPresent())
  54. {
  55. return;
  56. }
  57. // Select one of the cards
  58. if ( ! mfrc522.PICC_ReadCardSerial())
  59. {
  60. return;
  61. }
  62. //Show UID on serial monitor
  63. Serial.print("UID tag :");
  64. String content= "";
  65. byte letter;
  66. for (byte i = 0; i < mfrc522.uid.size; i++)
  67. {
  68. Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
  69. Serial.print(mfrc522.uid.uidByte[i], HEX);
  70. content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
  71. content.concat(String(mfrc522.uid.uidByte[i], HEX));
  72. }
  73. Serial.println();
  74. Serial.print("Message : ");
  75. content.toUpperCase();
  76. if (content.substring(1) == "20 90 E6 89") //change here the UID of the card/cards that you want to give access
  77. {
  78.  
  79.  
  80. Serial.println("card matched");
  81. Serial.println();
  82. screen.clear();
  83. screen.print (" card matched");
  84. delay (2000);
  85. screen.clear ();
  86. screen.print ("enter passcode");
  87. int i=0;
  88. while (i<4)
  89. {
  90. key_pressed = keypad_key.getKey(); // Storing keys
  91.  
  92. if (key_pressed)
  93. {
  94. password[i++] = key_pressed; // Storing in password variable
  95. screen.print("*");
  96. delay(5);
  97. }
  98. }
  99. delay(200);
  100. if (!(strncmp(password, initial_password, 4))) // If password is matched
  101. {
  102. screen.clear();
  103. screen.print("Pass Accepted");
  104. Tahm.write(90); // Door Opened
  105. digitalWrite(greenLed, HIGH);
  106. delay(3000);
  107. digitalWrite(greenLed, LOW);
  108. Tahm.write(0); // Door Closed
  109. screen.clear();
  110. i = 0;
  111. msg();
  112. }
  113. else // If password is not matched
  114. {
  115. screen.clear();
  116. screen.print("Wrong Password ");
  117.  
  118. digitalWrite(redLed, HIGH);
  119. delay(3000);
  120.  
  121. digitalWrite(redLed, LOW);
  122. screen.clear();
  123. i = 0;
  124. msg();
  125. }
  126. }
  127.  
  128. //
  129. // Tahm.write (0);
  130. // delay (5000);
  131. // Tahm.write (179);
  132. // msg();
  133.  
  134. else {
  135. Serial.println("card denied");
  136. screen.clear();
  137. screen.print (" Byeee");
  138. delay(5000);
  139. msg();
  140. }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement