RFID Card Scanner for Auto Attendant

I am trying to use either an Arduino Leonardo or Pro Micro

Please read this before posting a programming question and follow the instructions regarding posting code unless your code really is partially in italics

It just doesn't function.

What does that mean?

What does it do? What does it not do that you want it to do?

 //look for new card
  if (mfrc522.PICC_IsNewCardPresent())
  {
    return;//got to start of loop if there is no card present
  }

I am not familiar with the library but this looks to me as though the program returns to the top of loop() if a card is present

Should it not be

  if (!mfrc522.PICC_IsNewCardPresent())

The code is all wrong in all sorts of ways.
First off the numbers of the cards should be stored as a single number in the unsigned long format.
Then when you read a card convert the bytes you get into the same sort of single variable. To see if you already have this tag then search through your names array using just a single if comparison.
Then you have a string array ( note NOT a String array ) holding the string you want to print when you get a match.

But before all that you need to build it up a bit at a time, not program the whole thing and hope it will work. Only a beginner does that and the odds of that working get vanishingly small as he program’s complexity increases.

Start of by simply reading a tag and printing it out. Then add the conversion to a long variable and printing it out. Then add the compare to a list of tags. Finally add the array of the words you want to print out.

That part was taken from the rfid example code for DumpInfo as shown below

from DumpInfo

 if ( ! mfrc522.PICC_IsNewCardPresent()) {
 return;
 }

From your code

  if (mfrc522.PICC_IsNewCardPresent()) {
 return;//got to start of loop if there is no card present
}

Spot the difference

For an extra clue look at my suggested code in reply #6

That part was taken from the rfid example code for DumpInfo

Problem is that that example is one of the worst examples you could possibly get.

I already tried that, and I don’t know if it is because they are HID iClass, but the unsigned long for all 40 cards are identical. It must use the UID in hex.

Then try an unsigned long long variable, that is 64 bits wide.

    card_ID[i] = mfrc522.uid.uidByte[i];
    if (card_ID[i] == Name01[i])

Why are you copying the UID byte to a new variable ?

Now what I suspect is the real problem. Surely you need to compare the whole of the UID read from the card with the name rather than just the first byte. Even if the code works then what if 2 or more UIDs on the cards have the same first byte ?

As to using goto, just don't do it

You are definitely correct with the first byte problem, would this fix it?

If you insist on on doping the comparison byte by byte rather than comparing the whole number then no, it won’t fix it. You would need to test each byte of the UID read from the card against each byte of the stored IDs and keep track of which ones matched up to the current byte in the array. Only when one matched every byte would you know that you had an actual match.

Look back at post #7 for a better way to store and compare the data and an incremental way to approach the problem.

Your code to compare ids does not make sense; try this way

Disclaimer: it only works (if it works, not tested…) with 4 bytes ids

// check if card id is equal to name id; only works for 4 bytes ids
bool SameId(byte *cardId, byte *nameId)
{
	if (mfrc522.uid.size != 4)
	{
		// error here, nameId is 4 bytes, cardId is not 4 bytes
		Keyboard.println("Wrong id length, only 4 bytes ids accepted"); 
		return(false);
	}
	
	for (int i = 0; i < mfrc522.uid.size; i++) 
            if(cardId[i] != nameId[i])
      	        return( false );
      	
    return(true);  	
}

void loop() 
{
 	//look for new card
  	if (!mfrc522.PICC_IsNewCardPresent()) {
 		return;//got to start of loop if there is no card present
	}
	
	// Select one of the cards
	if (!mfrc522.PICC_ReadCardSerial()) {
		return;//if read card serial(0) returns 1, the uid struct contains the ID of the read card.
	}
	
	if (SameId(mfrc522.uid.uidByte, Name01)) 
           Keyboard.println("First Employee");

	else if (SameId(mfrc522.uid.uidByte, Name02)) 
           Keyboard.println("Second Employee");

	else if (SameId(mfrc522.uid.uidByte, Name03)) 
           Keyboard.println("Third Employee");

	delay(8000);
}

That works very well for what I need.

I thought you wanted 40 tags, surely you are not going to repeat that code over and over?

byte Name01[16]={0x5E,0x9A,0xF9,0x6A};//first UID card

Happy to waste 12 bytes per entry?