Advertisement
safwan092

Untitled

Feb 3rd, 2023
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 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. if(digitalRead(button) == 0){
  35. myservo.write( 90 );
  36. delay(7500);
  37. myservo.write( 0 );
  38. }
  39. // Look for new cards
  40. if ( ! mfrc522.PICC_IsNewCardPresent())
  41. {
  42. return;
  43. }
  44. // Select one of the cards
  45. if ( ! mfrc522.PICC_ReadCardSerial())
  46. {
  47. return;
  48. }
  49. //Show UID on serial monitor
  50. Serial.print("UID tag :");
  51. String content= "";
  52. byte letter;
  53. for (byte i = 0; i < mfrc522.uid.size; i++)
  54. {
  55. Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
  56. Serial.print(mfrc522.uid.uidByte[i], HEX);
  57. content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
  58. content.concat(String(mfrc522.uid.uidByte[i], HEX));
  59. }
  60. Serial.println();
  61. Serial.print("Message : ");
  62. content.toUpperCase();
  63. if (content.substring(1) == "63 4D 70 09") //change here the UID of the card
  64. {
  65. Serial.println("Authorized access");
  66. Serial.println();
  67. myservo.write( 90 );
  68. delay(7500);
  69. myservo.write( 0 );
  70.  
  71. }
  72.  
  73. else {
  74. Serial.println(" Access denied");
  75.  
  76.  
  77. delay(DENIED_DELAY);
  78.  
  79.  
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement