Advertisement
safwan092

Untitled

Dec 5th, 2023
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 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 servo_PIN 8
  8.  
  9. String user1ID = "14 4A 6D 2B";
  10. String user2ID = "39 4B C8 B8";
  11.  
  12. Servo myservo;
  13. MFRC522 mfrc522(SS_PIN, RST_PIN);
  14.  
  15. void setup()
  16. {
  17.  
  18. Serial.begin(9600); // Initiate a serial communication
  19. SPI.begin(); // Initiate SPI bus
  20. mfrc522.PCD_Init(); // Initiate MFRC522
  21. Serial.println("Approximate your card to the reader...");
  22. Serial.println();
  23. myservo.attach(servo_PIN);
  24. myservo.write(0);
  25. }
  26.  
  27. void loop() {
  28. // Look for new cards
  29. if ( ! mfrc522.PICC_IsNewCardPresent())
  30. {
  31. return;
  32. }
  33.  
  34. // Select one of the cards
  35. if ( ! mfrc522.PICC_ReadCardSerial())
  36. {
  37. return;
  38. }
  39.  
  40. //Show UID on serial monitor
  41. Serial.println ("");
  42. Serial.println("UID tag :");
  43. String content = "";
  44. byte letter;
  45. for (byte i = 0; i < mfrc522.uid.size; i++)
  46. {
  47. content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
  48. content.concat(String(mfrc522.uid.uidByte[i], HEX));
  49. content.toUpperCase();
  50. }
  51. Serial.println(content.substring(1));
  52. if (content.substring(1) == user1ID || content.substring(1) == user2ID) {
  53. myservo.write(90);
  54. delay(2000);
  55. myservo.write(0);
  56. delay(1000);
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement