safwan092

Untitled

Mar 27th, 2022
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.54 KB | None | 0 0
  1. //Studant Tag ---> 29 EC 2A B9
  2. //Dr Card #1 ---> 22 AC 75 34
  3. //Dr Card #2 ---> B6 BC 72 2B
  4. //Dr Card #3 ---> C0 6B BB 32
  5. //Dr Card #4 ---> C0 BD B6 32
  6. /*
  7. RFID Cards x5 [All Open] ✔
  8. Button [To Enter with No CARD] ✔
  9. LCD 20*4 [Show (IN#)+(OUT#)+(Current#)] ✔
  10. IR Sensor [Exit] ✔
  11. Servo_IN ✔
  12. Servo_OUT ✔
  13. */
  14. #include <SPI.h>
  15. #include <Wire.h>
  16. #include <Servo.h>
  17. #include <MFRC522.h>
  18. #include <LiquidCrystal_I2C.h>
  19.  
  20. #define SS_PIN 10
  21. #define RST_PIN 9
  22. #define button_PIN 8
  23. #define exit_PIN 7
  24.  
  25. Servo servoIN; //5
  26. Servo servoOUT; //6
  27. MFRC522 mfrc522(SS_PIN, RST_PIN);
  28. LiquidCrystal_I2C lcd(0x27, 20, 4);
  29.  
  30. int INcount = 0;
  31. int OUTcount = 0;
  32. int CurrentCount = 0;
  33. int exit_status = 0;
  34. int button_status = 0;
  35.  
  36. void setup() {
  37. Serial.begin(9600);
  38. pinMode(button_PIN, INPUT);
  39. pinMode(exit_PIN, INPUT);
  40. SPI.begin();
  41. mfrc522.PCD_Init();
  42. servoIN.attach(5);
  43. servoOUT.attach(6);
  44. servoIN.write(0);
  45. servoOUT.write(0);
  46. lcd.init();
  47. lcd.init();
  48. lcd.backlight();
  49. lcd.setCursor(0, 0);
  50. lcd.print("Starting...");
  51. delay(1000);
  52. lcd.setCursor(0, 0);
  53. lcd.print("Total Inside: ");
  54. lcd.print(CurrentCount);
  55. lcd.setCursor(0, 1);
  56. lcd.print("Total IN: ");
  57. lcd.print(INcount);
  58. lcd.setCursor(0, 2);
  59. lcd.print("Total OUT: ");
  60. lcd.print(OUTcount);
  61.  
  62. }
  63.  
  64. void loop() {
  65.  
  66. lcd.setCursor(0, 0);
  67. lcd.print("Total Inside: ");
  68. lcd.print(CurrentCount);
  69. lcd.print(" ");
  70. lcd.setCursor(0, 1);
  71. lcd.print("Total IN: ");
  72. lcd.print(INcount);
  73. lcd.print(" ");
  74. lcd.setCursor(0, 2);
  75. lcd.print("Total OUT: ");
  76. lcd.print(OUTcount);
  77. lcd.print(" ");
  78.  
  79. button_status = digitalRead(button_PIN);
  80. exit_status = digitalRead(exit_PIN);
  81.  
  82. if ( button_status > 0) {
  83. // Open IN Gate
  84. INcount = INcount + 1;
  85. CurrentCount = INcount - OUTcount;
  86. servoIN.write(90);
  87. delay(3000);
  88. servoIN.write(0);
  89. }
  90. if (exit_status == 0) {
  91. // Open OUT Gate
  92. OUTcount = OUTcount + 1;
  93. CurrentCount = INcount - OUTcount;
  94. if (CurrentCount < 0) {
  95. CurrentCount = 0;
  96. OUTcount = OUTcount - 1;
  97. }
  98. servoOUT.write(90);
  99. delay(3000);
  100. servoOUT.write(0);
  101. }
  102.  
  103. if ( ! mfrc522.PICC_IsNewCardPresent()) {
  104. return;
  105. }
  106.  
  107. if ( ! mfrc522.PICC_ReadCardSerial() ) {
  108. return;
  109. }
  110. String content = "";
  111. byte letter;
  112. for (byte i = 0; i < mfrc522.uid.size; i++) {
  113. Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
  114. Serial.print(mfrc522.uid.uidByte[i], HEX);
  115. content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
  116. content.concat(String(mfrc522.uid.uidByte[i], HEX));
  117. }
  118. Serial.println();
  119. content.toUpperCase();
  120. //Studant Tag ---> 29 EC 2A B9
  121. //Dr Card #1 ---> 22 AC 75 34
  122. //Dr Card #2 ---> B6 BC 72 2B
  123. //Dr Card #3 ---> C0 6B BB 32
  124. //Dr Card #4 ---> C0 BD B6 32
  125. // 1 2 3 4 5
  126. if (content.substring(1) == "29 EC 2A B9" || content.substring(1) == "22 AC 75 34" || content.substring(1) == "B6 BC 72 2B" || content.substring(1) == "C0 BD B6 32" || content.substring(1) == "C0 6B BB 32")
  127. {
  128. // Open IN Gate
  129. INcount = INcount + 1;
  130. CurrentCount = INcount - OUTcount;
  131. servoIN.write(90);
  132. delay(3000);
  133. servoIN.write(0);
  134. }
  135. else
  136. {
  137. // Don't Open IN Gate
  138. servoIN.write(0);
  139. }
  140.  
  141. delay(100);
  142. }
Advertisement
Add Comment
Please, Sign In to add comment