Advertisement
safwan092

Untitled

Oct 29th, 2023
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <MFRC522.h>
  3. #include <LiquidCrystal_I2C.h>
  4.  
  5. // Blue Tag = D9 B8 21 B9
  6. // White Card = D0 3A ED 32
  7.  
  8. #define SS_PIN 27 /*Slave Select Pin*/
  9. #define RST_PIN 26 /*Reset Pin for RC522*/
  10.  
  11. MFRC522 mfrc522(SS_PIN, RST_PIN);
  12. LiquidCrystal_I2C lcd(0x27, 16, 2);
  13.  
  14. void setup() {
  15. Serial.begin(9600); /*Serial Communication begin*/
  16. lcd.init();
  17. lcd.backlight();
  18. lcd.setCursor(0, 0);
  19. lcd.print("Hello, World!");
  20. SPI.begin(); /*SPI communication initialized*/
  21. mfrc522.PCD_Init(); /*RFID sensor initialized*/
  22. Serial.println("Put your card to the reader...");
  23. Serial.println();
  24. delay(1000);
  25. lcd.clear();
  26. }
  27.  
  28. void loop() {
  29. /*Look for the RFID Card*/
  30. if ( ! mfrc522.PICC_IsNewCardPresent())
  31. {
  32. return;
  33. }
  34. /*Select Card*/
  35. if ( ! mfrc522.PICC_ReadCardSerial())
  36. {
  37. return;
  38. }
  39. /*Show UID for Card/Tag on serial monitor*/
  40. Serial.print("UID tag :");
  41. String content = "";
  42. byte letter;
  43. for (byte i = 0; i < mfrc522.uid.size; i++)
  44. {
  45. Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
  46. Serial.print(mfrc522.uid.uidByte[i], HEX);
  47. content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
  48. content.concat(String(mfrc522.uid.uidByte[i], HEX));
  49. }
  50. Serial.println();
  51. Serial.print("Message : ");
  52. content.toUpperCase();
  53.  
  54. lcd.setCursor(0, 0);
  55. lcd.print(content.substring(1));
  56.  
  57. if (content.substring(1) == "D0 3A ED 32")
  58. {
  59. Serial.println("Authorized access");
  60. Serial.println();
  61. }
  62. else {
  63. Serial.println(" Access denied");
  64. }
  65. delay(1000);
  66. lcd.clear();
  67. }//end of Loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement