weinerm21

Untitled

Jun 21st, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <MFRC522.h>
  3.  
  4. #define SS_PIN 10
  5. #define RST_PIN 9
  6. MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
  7.  
  8. void setup()
  9. {
  10. Serial.begin(9600); // Initiate a serial communication
  11. SPI.begin(); // Initiate SPI bus
  12. mfrc522.PCD_Init(); // Initiate MFRC522
  13. Serial.println("Put your card to the reader...");
  14. Serial.println();
  15.  
  16. }
  17. void loop()
  18. {
  19. // Look for new cards
  20. if ( ! mfrc522.PICC_IsNewCardPresent())
  21. {
  22. return;
  23. }
  24. // Select one of the cards
  25. if ( ! mfrc522.PICC_ReadCardSerial())
  26. {
  27. return;
  28. }
  29. //Show UID on serial monitor
  30. Serial.print("UID tag :");
  31. String content= "";
  32. byte letter;
  33. for (byte i = 0; i < mfrc522.uid.size; i++)
  34. {
  35. Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
  36. Serial.print(mfrc522.uid.uidByte[i], HEX);
  37. content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
  38. content.concat(String(mfrc522.uid.uidByte[i], HEX));
  39. }
  40. Serial.println();
  41. Serial.print("Message : ");
  42. content.toUpperCase();
  43. if (content.substring(1) == "42 44 49 0D") //change here the UID of the card/cards that you want to give access
  44. {
  45. Serial.println("Authorized access");
  46. Serial.println();
  47. delay(3000);
  48. }
  49. if (content.substring(1) == "FA E8 BE 49") //change here the UID of the card/cards that you want to give access
  50. {
  51. Serial.println("Authorized access");
  52. Serial.println();
  53. delay(3000);
  54. }
  55. else {
  56. Serial.println(" Access denied");
  57. delay(3000);
  58. }
  59. }
Add Comment
Please, Sign In to add comment