Advertisement
lasthunter657

code on the internet

May 18th, 2021
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <MFRC522.h>
  3. #include <LiquidCrystal.h>
  4.  
  5. #define RST_PIN 9
  6. #define SS_PIN 10
  7.  
  8. byte readCard[4];
  9. String MasterTag = "20C3935E"; // REPLACE this Tag ID with your Tag ID!!!
  10. String tagID = "";
  11.  
  12. // Create instances
  13. MFRC522 mfrc522(SS_PIN, RST_PIN);
  14. LiquidCrystal lcd(7, 6, 5, 4, 3, 2); //Parameters: (rs, enable, d4, d5, d6, d7)
  15.  
  16. void setup()
  17. {
  18. // Initiating
  19. SPI.begin(); // SPI bus
  20. mfrc522.PCD_Init(); // MFRC522
  21. lcd.begin(16, 2); // LCD screen
  22.  
  23. lcd.clear();
  24. lcd.print(" Access Control ");
  25. lcd.setCursor(0, 1);
  26. lcd.print("Scan Your Card>>");
  27. }
  28.  
  29. void loop()
  30. {
  31.  
  32. //Wait until new tag is available
  33. while (getID())
  34. {
  35. lcd.clear();
  36. lcd.setCursor(0, 0);
  37.  
  38. if (tagID == MasterTag)
  39. {
  40.  
  41. lcd.print(" Access Granted!");
  42. // You can write any code here like opening doors, switching on a relay, lighting up an LED, or anything else you can think of.
  43. }
  44. else
  45. {
  46. lcd.print(" Access Denied!");
  47. }
  48.  
  49. lcd.setCursor(0, 1);
  50. lcd.print(" ID : ");
  51. lcd.print(tagID);
  52.  
  53. delay(2000);
  54.  
  55. lcd.clear();
  56. lcd.print(" Access Control ");
  57. lcd.setCursor(0, 1);
  58. lcd.print("Scan Your Card>>");
  59. }
  60. }
  61.  
  62. //Read new tag if available
  63. boolean getID()
  64. {
  65. // Getting ready for Reading PICCs
  66. if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue
  67. return false;
  68. }
  69. if ( ! mfrc522.PICC_ReadCardSerial()) { //Since a PICC placed get Serial and continue
  70. return false;
  71. }
  72. tagID = "";
  73. for ( uint8_t i = 0; i < 4; i++) { // The MIFARE PICCs that we use have 4 byte UID
  74. //readCard[i] = mfrc522.uid.uidByte[i];
  75. tagID.concat(String(mfrc522.uid.uidByte[i], HEX)); // Adds the 4 bytes in a single String variable
  76. }
  77. tagID.toUpperCase();
  78. mfrc522.PICC_HaltA(); // Stop reading
  79. return true;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement