I don't understand why change uidList[reader] variable, when doesn't run more to the else. I use in this test only the "0" reader.

First loop go to the "else" and fill the uid to uidList[reader]. (good) Second loop go to the "if" because the two uid is equal.(good)

I remove NFC and place the other, but the uidList[reader] updated immediately to the new UID, not in the "else". Never go again to else. Why?

#define NR_OF_READERS   2
byte* uidList[NR_OF_READERS]; 
MFRC522 mfrc522[NR_OF_READERS];   // Create MFRC522 instance.
void loop() {
  for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {

     dump_byte_array(uidList[0], 8); 
     dump_byte_array(uidList[1], 8);

   if (mfrc522[reader].PICC_IsNewCardPresent() &&     mfrc522[reader].PICC_ReadCardSerial()) {

     dump_byte_array(uidList[0], 8); //WHY UPDATED HERE???
     dump_byte_array(uidList[1], 8);

     if (uidList[reader] == mfrc522[reader].uid.uidByte) {

        Serial.println(F("Same NFC"));
        dump_byte_array(uidList[0], 8); 
        dump_byte_array(uidList[1], 8);

     } else {

        Serial.println(F("Other NFC in this reader"));

        uidList[reader] = mfrc522[reader].uid.uidByte; 

        dump_byte_array(uidList[0], 8); 
        dump_byte_array(uidList[1], 8);



void dump_byte_array(byte *buffer, byte bufferSize) {
  for (byte i = 0; i < bufferSize; i++) {
    Serial.print(buffer[i] < 0x10 ? " 0" : " ");
    Serial.print(buffer[i], HEX);

When I placed the new NFC in the reader, this debug appear on serial monitor.

 DF 6D 05 D2 00 00 00 00 //old NFC uid it's good

 AB 00 6C 02 F0 21 00 00

 FF 2C 02 69 00 00 00 00 //WHY UPDATED HERE???

 AB 00 6C 02 F0 21 00 00

Same NFC

 FF 2C 02 69 00 00 00 00 

 AB 00 6C 02 F0 21 00 00

Thanks any idea.

closed as unclear what you're asking by Edgar Bonet, James Waldby - jwpat7, Dat Ha, Mattia, brtiberio Nov 16 '16 at 8:45

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • The question isn't clear enough for me to understand what you are asking. – James Waldby - jwpat7 Nov 7 '16 at 19:27
  • Why change uidList[reader] without "else". Without this: uidList[reader] = mfrc522[reader].uid.uidByte; – Cipo Nov 7 '16 at 20:03

Well, it's easy, as you are using pointers. If the original place gets changed, you can see changed value because you don't have your own copy.

Your if statement is also wrong, as you are comparing two pointers here. They will be different at the first time comparation, but after the assigment they are unlikely to change.

The solution is using:

byte uidList[NR_OF_READERS][8]; // better to use some constant value instead of magic number

and memcpy for making a copy and memcmp for comparing its content. Both are from <cstring> include

  • Thx, you're right, but what is the solution? How do I compare the value, not the pointer in this code? – Cipo Nov 7 '16 at 20:28
  • @Cipo You've to have your own space to store those values and you've to use the right functions for copying and comparing these values (or make your own). Added into the answer. – KIIV Nov 7 '16 at 20:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.