Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Wire.h>
- #include <MFRC522.h>
- #include <LiquidCrystal_I2C.h>
- int counter = 0;
- unsigned long startMillis;
- unsigned long currentMillis;
- const unsigned long period = 30000;
- LiquidCrystal_I2C lcd(0x27, 16, 2);
- #define SS_PIN 10
- #define RST_PIN 9
- MFRC522 mfrc522(SS_PIN, RST_PIN);
- void setup()
- {
- startMillis = millis();
- Serial.begin(9600);
- SPI.begin();
- mfrc522.PCD_Init();
- Serial.println("Approximate your card to the reader...");
- Serial.println();
- lcd.init();
- lcd.init();
- lcd.backlight();
- lcd.setCursor(0, 0);
- lcd.print("UID tag :");
- }
- void loop(){
- currentMillis = millis();
- if ((currentMillis - startMillis >= period) && (counter > 0)) {
- counter = 0;
- Serial.println("Counter is reset after 30 seconds");
- startMillis = currentMillis;
- }
- if (counter > setNumb) {
- Serial.println("Crowed Mangment !!");
- }
- // Look for new cards
- if ( ! mfrc522.PICC_IsNewCardPresent())
- {
- return;
- }
- // Select one of the cards
- if ( ! mfrc522.PICC_ReadCardSerial())
- {
- return;
- }
- //Show UID on serial monitor
- Serial.println ("");
- Serial.println("UID tag :");
- String content = "";
- byte letter;
- for (byte i = 0; i < mfrc522.uid.size; i++)
- {
- content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
- content.concat(String(mfrc522.uid.uidByte[i], HEX));
- content.toUpperCase();
- }
- Serial.println(content.substring(1));
- lcd.setCursor(0, 1);
- lcd.print(content.substring(1));
- counter = counter + 1;
- delay(500);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement