How to add more than one UID tag in RFID

Hello everyone,

I am new to this forum and i need some guidance on how to add more than one RFID UID tag so that whenever i tap valid UID tag it will print “Access granted” without manually add each card UID tag for same condition.
Below are my full coding:

// Include required libraries
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <MFRC522.h>
#include <Wire.h>
#include <Ultrasonic.h>

// Create instances
LiquidCrystal_I2C lcd(0x27, 16, 2);
MFRC522 mfrc522(10, 9); // MFRC522 mfrc522(SS_PIN, RST_PIN)

Ultrasonic ultrasonic(6,7);//Define pins ultrasonic(trig,echo)

String tagUID = "89 ED 52 D3"; 
int distance;
int count = 5;

void setup() 
{
  lcd.init();   // LCD screen
  lcd.backlight();
  SPI.begin();      // Init SPI bus
  mfrc522.PCD_Init();   // Init MFRC522
  lcd.clear();

  lcd.setCursor(0, 0);
  lcd.print(" Welcome ");
  lcd.setCursor(0, 1);
  lcd.print(" Show Your Tag ");
}

void loop() 
{
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent()) 
  {
    return;
  }

  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) 
  {
    return;
  }

  //Reading from the card
  String tag = "";
  for (byte i = 0; i < mfrc522.uid.size; i++)
  {
    tag.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
    tag.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  tag.toUpperCase();

  //Checking the card
  if (tag.substring(1) == tagUID) 
  {
    // If UID of tag is matched.
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Access Granted");
    lcd.setCursor(0, 1);
    lcd.print(" Hello ");
    delay(3000); 
    lcd.clear();  
  }

  else
  {
    // If UID of tag is not matched.
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(" Invalid Tag ");
    lcd.setCursor(0, 1);
    lcd.print("Access Denied");
    delay(3000);
  }

}

I need to add one more UID tag code here so that both card is valid for same condition.
Anyone help me on this

 String tagUID = "89 ED 52 D3";

Thank you.

o that whenever i tap valid UID tag it will print "Access granted" without manually add each card UID tag for same condition.

Use an array of tag values - NOT an array of Strings, though. There is no excuse for converting a 4 byte array to a String, just so you can use the == operator. memcmp() will compare two byte arrays.

Thanks for your kind information,

Sorry to say, i really don’t have idea on how to use array of tag values. If can give any example so i can follow up. This is first time i use RFID reader, I don’t have much knowledge on this.

Please give me some guidance. Thank you

Sorry to say, i really don’t have idea on how to use array of tag values.

Then you’ll be stuck with your stupid “convert a byte array to a resource-wasting String” process, and having many Strings to compare to. You could have an array of Strings…

Or, you could ask Mr. Google how other people have solved this issue. You can’t really believe that you are the first person that wants to support more than one tag.