weinerm21

Untitled

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