Need help adding multiple RFID cards to whitelist.

Hello!
Currently creating an RFID door lock, and was wondering how I can adapt my code to allow multiple cards to enter.
I'm using an RC522 module to read the cards, some LEDs, and a buzzer along with an Arduino UNO.
Any help appreciated, and if anything else is needed to help, please let me know!
Thanks!

#include <RFID.h>

/*
* Read a card using a mfrc522 reader on your SPI interface
* Pin layout should be as follows (on Arduino Uno):
* MOSI: Pin 11 / ICSP-4
* MISO: Pin 12 / ICSP-1
* SCK: Pin 13 / ISCP-3
* SS/SDA: Pin 10
* RST: Pin 9
*/

#include <SPI.h>
#include <RFID.h>

#define SS_PIN 10
#define RST_PIN 9

RFID rfid(SS_PIN,RST_PIN);


int green = 7;
int red = 8;
int power = 2;
int buzzer = 4; 
int serNum[5];
int cards[][10] = {
  {180,238,165,189,66}
  
};

bool access = false;

void setup(){

    Serial.begin(9600);
    SPI.begin();
    rfid.init();

    pinMode(green, OUTPUT);
    pinMode(red, OUTPUT);

    digitalWrite(green, LOW);
    digitalWrite(red, LOW);
   
}

void loop(){
    
    if(rfid.isCard()){
    
        if(rfid.readCardSerial()){
            Serial.print(rfid.serNum[0]);
            Serial.print(" ");
            Serial.print(rfid.serNum[1]);
            Serial.print(" ");
            Serial.print(rfid.serNum[2]);
            Serial.print(" ");
            Serial.print(rfid.serNum[3]);
            Serial.print(" ");
            Serial.print(rfid.serNum[4]);
            Serial.println("");
            
            for(int x = 0; x < sizeof(cards); x++){
              for(int i = 0; i < sizeof(rfid.serNum); i++ ){
                  if(rfid.serNum[i] != cards[x][i]) {
                      access = false;
                      break;
                  } else {
                      access = true;
                  }
              }
              if(access) break;
            }
           
        }
        
       if(access){
           tone(buzzer, 1000);
           Serial.println("Welcome!");
           digitalWrite(green, HIGH); 
           delay(1000);
           digitalWrite(green, LOW);
           noTone(buzzer);
           
      } else {
           tone(buzzer, 500);
           Serial.println("Not allowed!"); 
           digitalWrite(red, HIGH);
           delay(1000);
           digitalWrite(red, LOW); 
           noTone(buzzer);     
           
       }        
    }
    
    
    
    rfid.halt();

}

I've never used that library. In my RFID projects I use the MFRC522.h library. When a card is read I just compare the value read with a list of predefined cards.

I don't see anywhere in your code where you are testing the card ID against anything. It looks like any card will open the lock.

You can get the source code in this tutorial for multiple RFID tags

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.