safwan092

bus rfid project

Oct 16th, 2018
141
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Created by TheCircuit
  3. Edited by Eng. Safwan Almaleh dawaerteam@gmail.com - 16/10/2018 - 5:50 PM
  4. */
  5.  
  6. String card[100] = {
  7.  
  8. "2D 81 1A 2B1"
  9. ,
  10. "2D 81 1A 2B" // ---> Valid
  11. ,
  12. "2D 81 1A 2B2"
  13. ,
  14. "2D 81 1A 2B3"
  15. ,
  16. "2D 81 1A 2B4"
  17. ,
  18. "2D 81 1A 2B5"
  19. ,
  20. "2D 81 1A 2B6"
  21. ,
  22. "2D 81 1A 2B7"
  23. ,
  24. "2D 81 1A 2B8"
  25. ,
  26. "2D 81 1A 2B9"
  27. ,
  28. "2D 81 1A 2B10"
  29. ,
  30. "2D 81 1A 2B11"
  31. ,
  32. ""
  33. ,
  34. ""
  35. ,
  36. ""
  37. ,
  38. ""
  39. ,
  40. ""
  41. ,
  42. ""
  43. ,
  44. ""
  45. ,
  46. ""
  47. ,
  48. ""
  49. ,
  50. ""
  51. ,
  52. ""
  53. ,
  54. ""
  55. ,
  56. ""
  57. ,
  58. ""
  59. ,
  60. ""
  61. ,
  62. ""
  63. ,
  64. ""
  65. ,
  66. ""
  67. ,
  68. ""
  69. ,
  70. ""
  71. ,
  72. ""
  73. ,
  74. ""
  75. ,
  76. ""
  77. ,
  78. ""
  79. ,
  80. ""
  81. ,
  82. ""
  83. ,
  84. ""
  85. ,
  86. ""
  87. ,
  88. ""
  89. ,
  90. ""
  91. ,
  92. ""
  93. ,
  94. ""
  95. ,
  96. ""
  97. ,
  98. ""
  99. ,
  100. ""
  101. ,
  102. ""
  103. ,
  104. ""
  105. ,
  106. ""
  107. ,
  108. ""
  109. ,
  110. ""
  111. ,
  112. ""
  113. ,
  114. "46 5D 6A 13" // ---> Valid
  115. ,
  116. ""
  117. ,
  118. ""
  119. ,
  120. ""
  121. ,
  122. ""
  123. ,
  124. ""
  125. ,
  126. ""
  127. ,
  128. ""
  129. ,
  130. ""
  131. ,
  132. ""
  133. ,
  134. ""
  135. ,
  136. ""
  137. ,
  138. ""
  139. ,
  140. ""
  141. ,
  142. ""
  143. ,
  144. ""
  145. ,
  146. ""
  147. ,
  148. ""
  149. ,
  150. ""
  151. ,
  152. ""
  153. ,
  154. ""
  155. ,
  156. ""
  157. ,
  158. ""
  159. ,
  160. ""
  161. ,
  162. ""
  163. ,
  164. ""
  165. ,
  166. ""
  167. ,
  168. ""
  169. ,
  170. ""
  171. ,
  172. ""
  173. ,
  174. ""
  175. ,
  176. ""
  177. ,
  178. ""
  179. ,
  180. ""
  181. ,
  182. ""
  183. ,
  184. ""
  185. ,
  186. ""
  187. ,
  188. ""
  189. ,
  190. ""
  191. ,
  192. ""
  193. ,
  194. ""
  195. ,
  196. ""
  197. ,
  198. ""
  199. ,
  200. ""
  201. ,
  202. ""
  203. ,
  204. ""
  205. ,
  206. ""
  207. };
  208.  
  209.  
  210. #define SS_PIN 4 //D2
  211. #define RST_PIN 5 //D1
  212. #include <SPI.h>
  213. #include <MFRC522.h>
  214. MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
  215. int count = 0;
  216. bool seats[100] = {0};
  217. int out = 0;
  218. void setup()
  219. {
  220. Serial.begin(115200); // Initiate a serial communication
  221. SPI.begin(); // Initiate SPI bus
  222. mfrc522.PCD_Init(); // Initiate MFRC522
  223. Serial.print("starting");
  224. }
  225. void loop()
  226. {
  227. // Look for new cards
  228. if ( ! mfrc522.PICC_IsNewCardPresent())
  229. {
  230. return;
  231. }
  232. // Select one of the cards
  233. if ( ! mfrc522.PICC_ReadCardSerial())
  234. {
  235. return;
  236. }
  237. String content = "";
  238. byte letter;
  239. for (byte i = 0; i < mfrc522.uid.size; i++)
  240. {
  241. // To show cards UUID, un-comment the next line
  242. Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");Serial.print(mfrc522.uid.uidByte[i], HEX);
  243.  
  244. content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
  245. content.concat(String(mfrc522.uid.uidByte[i], HEX));
  246. }
  247. content.toUpperCase();
  248. Serial.println();
  249. for (int j = 0; j < 100; j++) {
  250. if (content.substring(1) == card[j]) //change UID of the card that you want to give access
  251. {
  252. cLoop(j);
  253. }
  254. }
  255. }//end of loop
  256. void cLoop(int i) {
  257. if (seats[i] == 0 ) {
  258. seats[i] = 1;
  259. count = count + 1;
  260. }
  261. else {
  262. seats[i] = 0;
  263. count = count - 1;
  264. }
  265. Serial.print(" Count = ");
  266. Serial.println(count);
  267. delay(1000);
  268. }
RAW Paste Data