Advertisement
Guest User

lekker

a guest
Mar 19th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <MFRC522.h>
  3. #include <Servo.h>
  4.  
  5. #define SS_PIN 10
  6. #define RST_PIN 9
  7. #define LED_G 4 //define green LED pin
  8. #define LED_R 3 //define red LED
  9. #define BUZZER 6 //buzzer pin
  10. #define SERVOPIN = 2; //servo pin
  11. #define ACCESS_DELAY 2000
  12. #define DENIED_DELAY 1000
  13. MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
  14.  
  15. void setup()
  16. {
  17. Serial.begin(9600); // Initiate a serial communication
  18. SPI.begin(); // Initiate SPI bus
  19. mfrc522.PCD_Init(); // Initiate MFRC522
  20. pinMode(LED_G, OUTPUT);
  21. pinMode(LED_R, OUTPUT);
  22. pinMode(BUZZER, OUTPUT);
  23. noTone(BUZZER);
  24. Serial.println("Put your card to the reader...");
  25. Serial.println();
  26.  
  27. }
  28. void loop()
  29. {
  30. // Look for new cards
  31. if ( ! mfrc522.PICC_IsNewCardPresent())
  32. {
  33. return;
  34. }
  35. // Select one of the cards
  36. if ( ! mfrc522.PICC_ReadCardSerial())
  37. {
  38. return;
  39. }
  40. //Show UID on serial monitor
  41. Serial.print("UID tag :");
  42. String content = "";
  43. byte letter;
  44. for (byte i = 0; i < mfrc522.uid.size; i++)
  45. {
  46. Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
  47. Serial.print(mfrc522.uid.uidByte[i], HEX);
  48. content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
  49. content.concat(String(mfrc522.uid.uidByte[i], HEX));
  50. }
  51. Serial.println();
  52. Serial.print("Message : ");
  53. content.toUpperCase();
  54. if (content.substring(1) == "09 DC 8D AB") //change here the UID of the card/cards that you want to give access
  55. {
  56. Serial.println("Authorized access");
  57. Serial.println();
  58. delay(500);
  59. digitalWrite(LED_G, HIGH);
  60. delay(ACCESS_DELAY);
  61. digitalWrite(LED_G, LOW);
  62. }
  63.  
  64. else {
  65. Serial.println(" Access denied");
  66. digitalWrite(LED_R, HIGH);
  67. tone(BUZZER, 300);
  68. delay(ACCESS_DELAY);
  69. digitalWrite(LED_R, LOW);
  70. noTone(BUZZER);
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement