Advertisement
Garth0

Untitled

Dec 6th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 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. int Dword;
  8. int buzzerPin = 3;
  9. int led = 7;
  10. String incoming = "";
  11. void setup()
  12. {
  13. Serial.begin(9600); // Initiate a serial communication
  14. SPI.begin(); // Initiate SPI bus
  15. mfrc522.PCD_Init(); // Initiate MFRC522
  16. Serial.println("Approximate your card to the reader...");
  17. Serial.println();
  18. pinMode(buzzerPin, OUTPUT);
  19. pinMode(led,OUTPUT);
  20. }
  21. void loop()
  22. {
  23. Dword=Serial.read();
  24. // Look for new cards
  25. if ( ! mfrc522.PICC_IsNewCardPresent())
  26. {
  27. return;
  28. }
  29. // Select one of the cards
  30. if ( ! mfrc522.PICC_ReadCardSerial())
  31. {
  32. return;
  33. }
  34. //Show UID on serial monitor
  35. Serial.print("UID tag :");
  36. String content= "";
  37. byte letter;
  38. for (byte i = 0; i < mfrc522.uid.size; i++)
  39. {
  40. Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
  41. Serial.print(mfrc522.uid.uidByte[i], HEX);
  42. content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
  43. content.concat(String(mfrc522.uid.uidByte[i], HEX));
  44. }
  45. Serial.println();
  46. Serial.print("Message : ");
  47. content.toUpperCase();
  48. if (content.substring(1) == "B2 A4 C7 1C") //change here the UID of the card/cards that you want to give access
  49. {
  50. tone(buzzerPin,700,600) ;
  51. Serial.println("Authorized access");
  52. Serial.println();
  53. delay(3000);
  54. }
  55.  
  56. else {
  57. tone(buzzerPin,300,600) ;
  58. Serial.println(" Access denied");
  59. delay(3000);
  60. }
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement