Advertisement
safwan092

Untitled

Apr 10th, 2023
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Wire.h>
  3. #include <MFRC522.h>
  4. #include <LiquidCrystal_I2C.h>
  5.  
  6. int counter = 0;
  7. unsigned long startMillis;
  8. unsigned long currentMillis;
  9. const unsigned long period = 30000;
  10.  
  11. LiquidCrystal_I2C lcd(0x27, 16, 2);
  12. #define SS_PIN 10
  13. #define RST_PIN 9
  14.  
  15. MFRC522 mfrc522(SS_PIN, RST_PIN);
  16.  
  17. void setup()
  18. {
  19. startMillis = millis();
  20. Serial.begin(9600);
  21. SPI.begin();
  22. mfrc522.PCD_Init();
  23. Serial.println("Approximate your card to the reader...");
  24. Serial.println();
  25. lcd.init();
  26. lcd.init();
  27. lcd.backlight();
  28. lcd.setCursor(0, 0);
  29. lcd.print("UID tag :");
  30. }
  31.  
  32. void loop(){
  33. currentMillis = millis();
  34. if ((currentMillis - startMillis >= period) && (counter > 0)) {
  35. counter = 0;
  36. Serial.println("Counter is reset after 30 seconds");
  37. startMillis = currentMillis;
  38. }
  39. if (counter > setNumb) {
  40. Serial.println("Crowed Mangment !!");
  41. }
  42. // Look for new cards
  43. if ( ! mfrc522.PICC_IsNewCardPresent())
  44. {
  45. return;
  46. }
  47.  
  48. // Select one of the cards
  49. if ( ! mfrc522.PICC_ReadCardSerial())
  50. {
  51. return;
  52. }
  53.  
  54. //Show UID on serial monitor
  55. Serial.println ("");
  56. Serial.println("UID tag :");
  57. String content = "";
  58. byte letter;
  59. for (byte i = 0; i < mfrc522.uid.size; i++)
  60. {
  61. content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
  62. content.concat(String(mfrc522.uid.uidByte[i], HEX));
  63. content.toUpperCase();
  64. }
  65. Serial.println(content.substring(1));
  66. lcd.setCursor(0, 1);
  67. lcd.print(content.substring(1));
  68. counter = counter + 1;
  69. delay(500);
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement