Advertisement
safwan092

Untitled

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