# RFID multiple tags?

**URL:** <https://forum.arduino.cc/t/rfid-multiple-tags/656064>\
**Category:** Programming\
**Created:** [May 20, 2020, 3:30pm UTC](https://forum.arduino.cc/t/rfid-multiple-tags/656064 "2020-05-20T15:30:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![danhughed](https://avatars.discourse-cdn.com/v4/letter/d/13edae/32.png) [@danhughed](https://forum.arduino.cc/u/danhughed)\
**Post date:** [May 20, 2020, 3:30pm UTC](https://forum.arduino.cc/t/rfid-multiple-tags/656064/1 "2020-05-20T15:30:09Z")

</div>

i'm having trouble with writing code, i'm trying to self teach myself, but its not good well. have hacked bits of different code together,to make my alarm system project but i cant figure out how to add more then one RFID tag to the code. is it possible that someone can give us a hand trying to sort it thanks.

this is what have.

```cpp
/*
 Typical pin layout used:
  -----------------------------------------------------------------------------------------
              MFRC522      Arduino      Arduino    
              Reader/PCD  Uno/101      Nano v3    
  Signal      Pin          Pin          Pin       
  -----------------------------------------------------------------------------------------
  RST/Reset  RST          9            D9      orange   
  SPI SS      SDA(SS)      10            D10    yellow   
  SPI MOSI    MOSI        11 / ICSP-4  D11    green  
  SPI MISO    MISO        12 / ICSP-1  D12    blue  
  SPI SCK    SCK          13 / ICSP-3  D13    purple   
*/
#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance.
int RELAY = 8;
int REDLED = 7;
int GREENLED = 6;
int BUZZER = 5;

void setup()
{
  Serial.begin(9600);  // Initiate a serial communication
  SPI.begin();      // Initiate  SPI bus
  mfrc522.PCD_Init();  // Initiate MFRC522
  Serial.println("SHED DOOR.");
  Serial.println();
  pinMode (RELAY, OUTPUT);
  pinMode (REDLED, OUTPUT);
  pinMode (GREENLED, OUTPUT);
  pinMode (BUZZER, OUTPUT);
}

void loop()
{
  // 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.print("UID tag :");
  String content = "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++)
  {
    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc522.uid.uidByte[i], HEX);
    content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
    content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  Serial.println();
  Serial.print("Message : ");
  content.toUpperCase();
  if (content.substring(1) == "85 A5 B0 56") //change here the UID of the card/cards that you want to give access
  {
    Serial.println("Authorized access");
    Serial.println("Welcome Mr Hughes");
    digitalWrite (BUZZER, HIGH);
    delay(500);
    digitalWrite (BUZZER, LOW);
    digitalWrite (RELAY, HIGH);
    digitalWrite (GREENLED, HIGH);
    delay(10000);
    digitalWrite (RELAY, LOW);
    digitalWrite (GREENLED, LOW);
     
  }

  else  {
    Serial.println(" Access denied");
    digitalWrite (REDLED, HIGH);
    delay(3000);
    digitalWrite (REDLED, LOW);
  }

}

```

Moderator edit:  
`</mark> <mark>[code]</mark> <mark>`

`</mark> <mark>[/code]</mark> <mark>`  
tags added.

---

<div class="post-metadata">

**Author:** ![Grumpy\_Mike](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/grumpy_mike/32/213521_2.png) [@Grumpy\_Mike](https://forum.arduino.cc/u/Grumpy_Mike)\
**Post date:** [May 27, 2020, 10:17pm UTC](https://forum.arduino.cc/t/rfid-multiple-tags/656064/2 "2020-05-27T22:17:29Z")

</div>

The line

```cpp
 if (content.substring(1) == "85 A5 B0 56") //change here the UID of the card/cards that you want to give access

```

Should look for all the cards you want to have access to your system. If this is just a few use a compound if statement here with the OR function ||

```cpp
 if (content.substring(1) == "85 A5 B0 56" || content.substring(1) == "23 E5 B0 28" );

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 12:32am UTC](https://forum.arduino.cc/t/rfid-multiple-tags/656064/3 "2021-05-06T00:32:30Z")

</div>

Closed on May 6, 2021, 12:32am UTC


