safwan092

Project_10766_Code

Jan 23rd, 2023
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 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.  
  8. Servo servo1;
  9. Servo servo2;
  10. Servo servo3;
  11. Servo servo4;
  12. MFRC522 mfrc522(SS_PIN, RST_PIN);
  13.  
  14. void setup() {
  15. servo1.attach(2);
  16. servo2.attach(3);
  17. servo3.attach(4);
  18. servo4.attach(5);
  19. servo1.write(0);
  20. servo2.write(0);
  21. servo3.write(0);
  22. servo4.write(0);
  23. Serial.begin(9600);
  24. SPI.begin();
  25. mfrc522.PCD_Init();
  26. delay(4); // Optional delay. Some board do need more time after init to be ready, see Readme
  27. mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
  28. Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
  29. Serial.println("Starting...");
  30. Serial.println(F("Scan a Card"));
  31. }
  32.  
  33. void loop() {
  34. //Serial.println("welcome to the loop");
  35. if ( ! mfrc522.PICC_IsNewCardPresent()) {
  36. return;
  37. }
  38.  
  39. if ( ! mfrc522.PICC_ReadCardSerial() ) {
  40. return;
  41. }
  42. String content = "";
  43. byte letter;
  44. for (byte i = 0; i < mfrc522.uid.size; i++) {
  45. Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
  46. Serial.print(mfrc522.uid.uidByte[i], HEX);
  47. content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
  48. content.concat(String(mfrc522.uid.uidByte[i], HEX));
  49. }
  50. Serial.println();
  51. content.toUpperCase();
  52. //Tag #1 ID : 53 2A 52 B2 50 00 01
  53. //Tag #2 ID : 53 29 52 B2 50 00 01
  54. //Tag #3 ID : 53 28 52 B2 50 00 01
  55. //Tag #4 ID : 53 23 52 B2 50 00 01
  56. if (content.substring(1) == "53 2A 52 B2 50 00 01") {
  57. TagNo1Function();
  58. }
  59. else if (content.substring(1) == "53 29 52 B2 50 00 01") {
  60. TagNo2Function();
  61. }
  62. else if (content.substring(1) == "53 28 52 B2 50 00 01") {
  63. TagNo3Function();
  64. }
  65. else if (content.substring(1) == "53 23 52 B2 50 00 01") {
  66. TagNo4Function();
  67. }
  68.  
  69. }
  70.  
  71. void TagNo1Function() {
  72. servo1.write(90);
  73. delay(3000);
  74. servo1.write(0);
  75. }
  76.  
  77. void TagNo2Function() {
  78. servo2.write(90);
  79. delay(3000);
  80. servo2.write(0);
  81. }
  82.  
  83. void TagNo3Function() {
  84. servo3.write(90);
  85. delay(3000);
  86. servo3.write(0);
  87. }
  88.  
  89. void TagNo4Function() {
  90. servo4.write(90);
  91. delay(3000);
  92. servo4.write(0);
  93. }
Advertisement
Add Comment
Please, Sign In to add comment