rfid icon indicating copy to clipboard operation
rfid copied to clipboard

Up to 5 devices simultanious

Open Lennyz1988 opened this issue 8 years ago • 72 comments

I am posting this to describe my experience in trying to get 5 RFID devices (MFRC522) to work at the same time using 1 Arduino.

This is also relevant to these posts:

https://github.com/miguelbalboa/rfid/issues/191

https://github.com/miguelbalboa/rfid/issues/277

https://github.com/miguelbalboa/rfid/issues/263

After a lot of trial and error I got 5 devices to work simultaneously using this library.

  • Make sure to use quality cables! I used CAT5E UTP cables to connect the RFID devices to the Arduino.

  • I started with 5 cables with a total length of 40 meters. I could get 2 devices to work reliable but I could not use the other 3 devices. So I repositioned the Arduino and cut the cables to about 15 meters length total (5 cables, 3 meter each). Maybe if you would use even better quality cables you can increase the length of the cables.

  • Try multiple RFID cards. I noticed after a while that some cards would work on one device but were not recognized on another device.

  • Make sure to have 1 or 2 backup MFRC522. When I couldn't figure out why one device would not read the tags when connected, I swapped it with one of my backups and it started working. Keep in mind that the device that could not read the card still works when connected on my breadbord. So maybe there is just to much interference for that device.

So now after many hours of trial and error I got 5 devices to work reliably, without any extra components, WITHOUT a multiplexer, over a total cable length of 15 meters.

I hope this helps someone.

NOTE: I only tested that it could recognize the card UID. I did not test if it could read the actual data on the card because that's not required for my goals.

Lennyz1988 avatar Feb 22 '17 08:02 Lennyz1988

Hello ! We have the same problem it's realy annoying ! How did you manage to get 5 devices working ? can you show us the code in witch 5 devices work (what I have never seen) !!

masterleo avatar Apr 11 '17 12:04 masterleo

Help me on this issue here : http://arduino.stackexchange.com/questions/36982/multiple-mfrc522-rfid-reader-on-uno-bugs

masterleo avatar Apr 11 '17 12:04 masterleo

You can just use the standard ReadUidMultiReader example.

  • Add the additional ss pins in the code
  • add the ss pins to the "byte sspins"

That's it.

The code you posted makes no sense at all to me. I suggest you start from scratch.

If you cannot get it to work reliably because of the cable distance, then it's also an option to use 2 Arduino's connected by I2C or Serial and exchange the data between the Arduino's.

Lennyz1988 avatar Apr 11 '17 14:04 Lennyz1988

Hello, I'm working with 4 readers and it works ok, It's based on miguelbalboa's multi rfid example

bool getRFID(byte readern) { bool isPICCpresent = false; digitalWrite(RST_PIN, HIGH); // Get RC522 reader out of hard low power mode mfrc522[readern].PCD_Init(); // Init the reader if (mfrc522[readern].PICC_IsNewCardPresent() && mfrc522[readern].PICC_ReadCardSerial()) { memcpy(readedCard[readern], mfrc522[readern].uid.uidByte, 4); // Copy UID to a global array isPICCpresent = true; } mfrc522[readern].PICC_HaltA(); mfrc522[readern].PCD_StopCrypto1(); digitalWrite(RST_PIN, LOW); // return to hard low power mode return isPICCpresent; // returns TRUE if PICC is detected, false if not }

But I have a problem setting the gain, I tryed this after the PCD_init():

mfrc522[readern].PCD_SetAntennaGain(0x07);

and:

mfrc522[readern].PCD_SetRegisterBitMask(mfrc522[readern].RFCfgReg, (0x07<<4));

But when I try to change the gain, my readers can't read the rfid tags or read it sometimes. It is annoying that i can't setting the gain fine.

When I did a basic program to test the mfrc522 readers, setting the gain worked fine, but now with the multi-readers and the need of a loop with the PCD_Init() (I need to know that the card is present yet), it doesn't work!

I would appreciate some help. Thanks!

MDLSoft avatar Jun 07 '17 19:06 MDLSoft

i think i saw a snippet of this in a forum but it was deleted when i check back. can you post the entire .ino file so i can check with similar setup?

akeilox avatar Jun 08 '17 03:06 akeilox

Here is the .ino, this is a test setup, I have a more complex program comparing UIDs, storing it to eeprom, activating outputs and many others functions but the base is this, reading the UIDs of the PICC. I don't need access to PICC memory or do more advanced stuff, only read their UID and know when PICC is over the reader. You can see in the sketch where I tryed to set gain.

//******************************************************************************************
//**                     ARDUINO PRO MINI 3.3v 8MHz                                       **
//**                    GND  GND  VCC  RX   TX   /DTR                                     **
//**                 +--------------------------------+                                   **
//**                 |  [ ]  [ ]  [ ]  [ ]  [ ]  [ ]  |                                   **
//**                 |          SERIAL PORT           |                                   **
//**             D1  | [ ]1/TX                 RAW[ ] |   |                               **
//**             D0  | [ ]0/RX                 GND[ ] | <--> GND                          **
//**                 | [ ]RST        SCL/A5[ ] RST[ ] |                                   **
//**                 | [ ]GND        SDA/A4[ ] VCC[ ] |  --> VCC 3.3v                     **
//**             D2  | [ ]2/INT0    ___         A3[ ] |  --> SDA/SS reader #3             **
//**             D3  |~[ ]3/INT1   /   \        A2[ ] |  --> SDA/SS reader #2             **
//**             D4  | [ ]4       /PRO  \       A1[ ] |  --> SDA/SS reader #1             **
//**             D5  |~[ ]5       \ MINI/       A0[ ] |  --> SDA/SS reader #0             **
//**             D6  |~[ ]6        \___/    SCK/13[ ] |  --> SCK (Clock)                  **
//**             D7  | [ ]7          A7[ ] MISO/12[ ] |  <-- MISO (Master In Slave Out)   **
//**             B0  | [ ]8          A6[ ] MOSI/11[ ]~|  --> MOSI (Master Out Slave In)   **
//**             B1  |~[ ]9                  SS/10[ ]~|  --> RST All readers (for now)    **
//**                 |           [RST-BTN]            |                                   **
//**                 +--------------------------------+                                   **
//**              http://busyducks.com/ascii-art-arduinos                                 **
//**                                                                                      **
//**               MDLSoft(c) 2017   Test setup ver: 1.02                                 **
//******************************************************************************************

#include <SPI.h>
#include <MFRC522.h>
#include <string.h>

constexpr uint8_t NR_OF_READERS = 4;

constexpr uint8_t RST_PIN  = 10;
constexpr uint8_t SS_0_PIN = A0;
constexpr uint8_t SS_1_PIN = A1;
constexpr uint8_t SS_2_PIN = A2;
constexpr uint8_t SS_3_PIN = A3;

byte ssPins[] = {SS_0_PIN, SS_1_PIN, SS_2_PIN, SS_3_PIN};

byte readedCard[NR_OF_READERS][4];  // Matrix for storing UID over each reader
MFRC522 mfrc522[NR_OF_READERS];     // Create MFRC522 instances


void setup()
{
  Serial.begin(9600); // Initialize serial communications
  while (!Serial);    // Do nothing until serial connection is opened
  SPI.begin();        // Init SPI bus
  for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) 
   {
    mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN); // Init each MFRC522 card
   }
 pinMode(RST_PIN, OUTPUT);
 digitalWrite(RST_PIN, LOW);    // mfrc522 readers hard power down.
}


void loop() 
{
 for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) 
  {
    if(getRFID(reader))
    {
      Serial.print(F("Reader "));
      Serial.print(reader);
      Serial.print(F(": Card UID:"));
      printUID(readedCard[reader]);
      Serial.println();
    }
  }
delay(2000);
}

//******************** Routine for print 4 byte UID to serial ******************************
void printUID(byte *buffer){
for (byte i = 0; i < 4; i++){
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
Serial.print(buffer[i], HEX);}}
//********************************END OF ROUTINE********************************************

//************ Routine for scan readers and store the UIDs in readedCard array *************
bool getRFID(byte readern)
{
  bool isPICCpresent = false;
  digitalWrite(RST_PIN, HIGH);   // Get RC522 reader out of hard low power mode
  mfrc522[readern].PCD_Init();   // Init the reader
  //****** Trying to set antenna gain to max, erratic functioning of the readers ***********
  //mfrc522[readern].PCD_SetRegisterBitMask(mfrc522[readern].RFCfgReg, (0x07<<4)); 
  //mfrc522[readern].PCD_SetAntennaGain(0x04);
  // mfrc522[readern].PCD_ClearRegisterBitMask(mfrc522[readern].RFCfgReg, (0x07<<4));
  // mfrc522[readern].PCD_SetRegisterBitMask(mfrc522[readern].RFCfgReg, 0x07);
  //delay(50); 
  if (mfrc522[readern].PICC_IsNewCardPresent() && mfrc522[readern].PICC_ReadCardSerial())
    {
     memcpy(readedCard[readern], mfrc522[readern].uid.uidByte, 4); 
     isPICCpresent = true;
    }
  mfrc522[readern].PICC_HaltA();
  mfrc522[readern].PCD_StopCrypto1();
  digitalWrite(RST_PIN, LOW);    // return to hard low power mode
  return isPICCpresent;          // returns TRUE if PICC is detected, false if not
}
//********************************END OF ROUTINE********************************************

MDLSoft avatar Jun 08 '17 07:06 MDLSoft

I use Arduino UNO Board and i have a problem with two RFID by pin MOSI and MISO, i follow the code on top my comment, so can help me, i need to see your circuit thank you

Khamphai avatar Jun 11 '17 09:06 Khamphai

You shoul use 3.3v for the RFID readers, you could lower the UNO from 5v to 3.3v or use level shifters. Other than that is to have the connections right and as is a relatively high frequency you should take care about contacts in the breadboards or dupont wires. In my case, I soldered flat cables to have better conectivity.

You could show us your circuit, maybe we can help you with it.

MDLSoft avatar Jun 13 '17 12:06 MDLSoft

Hi there, I am looking to connect 6 RC522 RFID readers and I have wired them according to this image but I was wondering, do I have to also connect the 3.3V from the Arduino to each of the RC522 Readers as well? Thank you for your help! huuiu

roooney avatar Jun 14 '17 17:06 roooney

Yes, you have to use 3.3v to Vcc for every RC522. All the communication bus (MOSI, MISO and SCK) and select (SSn) should also work at 3.3v.

Maybe you have already though about this, but I suggest you try first with only one Rc522 reader and then add one by one. It's easier to find bugs and get working multiple rfid readers in the same bus. I haven't tried more than 4 readers but you shouldn't have any problems.

MDLSoft avatar Jun 14 '17 18:06 MDLSoft

Thank you @MDLSoft, so i'll dasiy chain all RC522's 3.3V like I would for other wires (MOSI, MISO, etc). Thank you!

roooney avatar Jun 14 '17 19:06 roooney

I was hoping I´d find what I´m looking for but sadly no... What I want it is also to use 5 readers, but like access control. Every rfid reader is programmed to ´allow´ 1 tag/card. So when all 5 tags are scanned by the proper reader, a realy switches. How do I do that? It's like combining acces control with multirfidreader but I don't know how to do it.

remconet avatar Jan 30 '18 22:01 remconet

Wouldn’t be too hard to do what you’re proposing… Of course the readers themselves are not actually ‘programmed’ to remember cards. This must be handled by your logic. One approach would be to store your ‘valid keys’ in the EEPROM of your MCU device…

Opening a relay thereafter is trivial. There are good demo sketches around for both of these elements.

Lou

On Jan 30, 2018, at 5:03 PM, remconet [email protected] wrote:

I was hoping I´d find what I´m looking for but sadly no... What I want it is also to use 5 readers, but like access control. Every rfid reader is programmed to ´allow´ 1 tag/card. So when all 5 tags are scanned by the proper reader, a realy switches. How do I do that? It's like combining acces control with multirfidreader but I don't know how to do it.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/miguelbalboa/rfid/issues/290#issuecomment-361749868, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJZOanhEEe6ya7ouC4XJXHDSBDg6aHQks5tP5HHgaJpZM4MIVfO.

DrLou avatar Jan 30 '18 22:01 DrLou

I've done 12 (at reasonable distance ~20ft)) cat 5e.

You should have no problem with 4,5 or 6.

I'd pull CS up though - I have never had much luck beyond 3 readers with CS floating. Sky is the limit if you pullup.

Also - I don't level shift. I've seen folks doing it, it's the right thing to do, but could not pull off level shifting beyond 1 reader. Could be the quality of the shifters I was using - I don't know. That said, the readers seem to work well at 5v signals - but I understand you are doing this at your own risk as 5v is over spec.

giz02 avatar Mar 08 '18 02:03 giz02

Heya giz02 - can you tell me what you mean by pull CS up? I assume you're pulling up a pin with a resister, but I don't recall a pin on the arduino called CD - what am I missing?

vogonsaudi avatar Apr 06 '18 03:04 vogonsaudi

Hello Everyone i have a question. is it important that all RFID reader have same Firmware? i want use 5 RFID ( RC522 ) with one arduino. when i join one RFID it work well and read cards. when i make it 2 RFID it work well yet and rad cards. but when i join 3 RFID, it don't work and have Error. my RFIDs version is: Reader 0: Firmware Version: 0x92 = v2.0 Reader 1: Firmware Version: 0x12 = (unknown) please help me with that

Thanks

amkamyab avatar Apr 20 '18 07:04 amkamyab

I also managed to make 5 RFID readers to work simultaneously with Arduino Uno and miguelbalboa's library. Check this repo https://github.com/Annaane/MultiRfid or this is a video that shows that's functional : https://www.youtube.com/watch?v=ahc8Yai_sWI

Annaane avatar Apr 27 '18 15:04 Annaane

@amkamyab I had the same issue before I initialized all CS pins to HIGH before the individual setup. Otherwise all RFID devices will respond simultaneously and you get crazy firmware readings.

thoka avatar May 09 '18 23:05 thoka

@thoka hello. may i ask you to explain more what i should do to fix this problem. and something else. how long distance can have my RFID cable. Thanks Amkamyab

amkamyab avatar Jun 30 '18 12:06 amkamyab

I also had this problem. I first had a project where I used 3 RFID readers and it worked fine. Later I had to rebuild my project, with 3 RFID readers from other manufacturers, and it didn't work. The new readers worked individually, but not combined.

I solved this by turning the readers | on, measure, off | one by one. This worked really well. The readers need about 20mA, which the digital pins can provide. So what you can do is: digitalWrite(1,HIGH); receiveData(); digitalWrite(1,LOW); for all readers.

!! BUT !! The readers need 3.3v, and the digital pins provide 5v. So I used a 3.3v regulator to convert the 5v to 3.3v. Otherwise the RFID readers might explode. I used the LD1117V33.

You can switch them really quickly and it still works. (I tried 10 readings per second).

Also, because of having to use one extra pin per reader now, the maximum amount of readers is 4 now on a normal Arduino.

I anyone needs more information on this, I'll gladly help out! Just message me

sjoerd1999 avatar Jul 25 '18 17:07 sjoerd1999

Dear Github Swarm, I've been looking into your reign whenever I needed help and found it without needing to ask. The time has come to approach you directly.

This is going to be a long one, just trying to explain the situation as good as possible.

First off, please don't be too harsh, my coding skills are almost none existent, and it takes me a really long time to understand what's happening in a code. While making progress, I'm happily spending more hours than necessary. The following code I have (partly) written myself and I am almost proud that it is indeed working (again partly). It is an escape room puzzle (or at least should be, once it works)

The Situation: An Arduino nano has 3 RFID readers attached. Each of those 3 RFID readers only shall read their specific RFID tag correctly. So for each reader, there is only one correct tag. We have 3 lights for each of those readers. A reader reads the correct tag - the corresponding light will shine. Once all 3 readers read their correct tags at the same time (and all 3 lights are shining) a Relais is activated to power(or depower) a 12V magnet for a small door. There is a timer involved, which works fine, once the readers work.

The Problem: When plugged in via USB it works perfectly fine.

When plugged in via 12V adapter it works as well, but ONLY every second or third time. Sometimes it works a couple of times in a row, then a couple of times not. I can't find a logic in the pattern (if one can call it a pattern)

One last fun fact: in the code below Reader#2 is initiated last, - this is the one that doesn't always work. It is ALWAYS the last initiated reader which doesn't work.

Why does it work when powered via USB, and then not always when powered via 12V VIN?

tags, Cables, Readers, Nanos have been replaced to make sure it's not a hardware error.

To come to an end- I appreciate all help I can get, so thank you in advance, best regards, Mani

#include <SPI.h>
#include <MFRC522.h>


#define SS_PIN 10
#define RST_PIN 9
#define SS_PIN2 8
#define SS_PIN3 7
#define LED_R 2 //define red LED
#define Light1 3
#define Light2 4
#define Light3 5
#define relais 6

MFRC522 mfrc1(SS_PIN, RST_PIN);   // Create mfrc1 instance.
MFRC522 mfrc2(SS_PIN2, RST_PIN);
MFRC522 mfrc3(SS_PIN3, RST_PIN);


int zustand1;
int zustand2;
int zustand3;

bool timerGestartet = false;
unsigned long timeAfter2Seconds = 0;

unsigned long currentTime = 0;


void setup()
{
  Serial.begin(9600);   // Initiate a serial communication

  SPI.begin();      // Initiate  SPI bus

  
  
  mfrc1.PCD_Init();
  mfrc3.PCD_Init();
  mfrc2.PCD_Init();

  zustand1 = 0;
  zustand2 = 0;
  zustand3 = 0;
   
   
 
  pinMode(Light1, OUTPUT);
  pinMode(LED_R, OUTPUT);
  pinMode(Light2, OUTPUT);
  pinMode(Light3, OUTPUT);
  pinMode(relais, OUTPUT);
  Serial.println("Put your card to the reader...");
  Serial.println();


}
void loop()
{

  
  
  reader1();
  reader2();
  reader3();

 zustand1 = digitalRead(Light1);
 zustand2 = digitalRead(Light2);
 zustand3 = digitalRead(Light3);

 currentTime = millis();

if((zustand1 == 1) && (zustand2 == 1) && (zustand3 == 1)) 

  {digitalWrite(relais,HIGH);
 
   
  }
  else{digitalWrite(relais,LOW);}

bool karteErkannt = (zustand1 == 1) || (zustand2 == 1) || (zustand3 == 1);

//  If any reader recognizes the correct tag AND if no timer has been started, we start one
if((timerGestartet == false) && (karteErkannt == true)) {
    timerGestartet = true;
    timeAfter2Seconds = currentTime + 2000;
}

if ((timerGestartet == true) && (currentTime > timeAfter2Seconds)) {

    digitalWrite(Light1,LOW);
    digitalWrite(Light2,LOW);
    digitalWrite(Light3,LOW);
    
    timerGestartet = false;
  }
  
}

 

void reader1()
{
  // Look for new cards
  if ( ! mfrc1.PICC_IsNewCardPresent())
  {
    
    return;
  }
  
  // Select one of the cards
  if ( ! mfrc1.PICC_ReadCardSerial())
  {
    return;
  }
  //Show UID on serial monitor
  
  Serial.print("UID tag :");
  String content = "";
  byte letter;
  for (byte i = 0; i < mfrc1.uid.size; i++)
  {
    Serial.print(mfrc1.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc1.uid.uidByte[i], HEX);
    content.concat(String(mfrc1.uid.uidByte[i] < 0x10 ? " 0" : " "));
    content.concat(String(mfrc1.uid.uidByte[i], HEX));
  }
  Serial.println();
  Serial.print("Message : ");
  content.toUpperCase();
  if (content.substring(1) == "40 A8 71 A3") //change here the UID of the card/cards that you want to give access
  {
    Serial.println("Authorized access");
    Serial.println();
    digitalWrite(Light1, HIGH);
   
  }
    

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


 
}

void reader2() {
  
  // Look for new cards
  if ( ! mfrc2.PICC_IsNewCardPresent())
  {
    return;
  }
  // Select one of the cards
  if ( ! mfrc2.PICC_ReadCardSerial())
  {
    return;
  }
  //Show UID on serial monitor
  Serial.print("UID tag :");
  String content = "";
  for (byte i = 0; i < mfrc2.uid.size; i++)
  {
    Serial.print(mfrc2.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc2.uid.uidByte[i], HEX);
    content.concat(String(mfrc2.uid.uidByte[i] < 0x10 ? " 0" : " "));
    content.concat(String(mfrc2.uid.uidByte[i], HEX));
  }
  Serial.println();
  Serial.print("Message : ");
  content.toUpperCase();
  if (content.substring(1) == "B0 CD C5 A3") //change here the UID of the card/cards that you want to give access
  {
    Serial.println("Authorized access");
    Serial.println();
    digitalWrite(Light2, HIGH);
    
  }

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

void reader3() {
  
  // Look for new cards
  if ( ! mfrc3.PICC_IsNewCardPresent())
  {
    return;
  }
  // Select one of the cards
  if ( ! mfrc3.PICC_ReadCardSerial())
  {
    return;
  }
  //Show UID on serial monitor
  Serial.print("UID tag :");
  String content = "";
  for (byte i = 0; i < mfrc3.uid.size; i++)
  {
    Serial.print(mfrc3.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc3.uid.uidByte[i], HEX);
    content.concat(String(mfrc3.uid.uidByte[i] < 0x10 ? " 0" : " "));
    content.concat(String(mfrc3.uid.uidByte[i], HEX));
  }
  Serial.println();
  Serial.print("Message : ");
  content.toUpperCase();
  if (content.substring(1) == "B0 A2 89 A7") //change here the UID of the card/cards that you want to give access
  {
    Serial.println("Authorized access");
    Serial.println();
    digitalWrite(Light3, HIGH);
   
  }

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

suimani avatar Aug 22 '18 18:08 suimani

Maybe the 12V isn't clean DC ? Like it isn't producing a constant 12V, but rather jumps back and forth around 12V. This could cause problems. I run MRFC522 RFID cards with a 9V battery all the time, and it works fine.

Other than that I don't know a reason why it doesn't work. Maybe the supply doesn't provide enough current? You can also try to use a 5V regulator to turn the 12V into 5V and run that into the 5V pin on the Arduino. You can also just use a powerbank to power it, but I understand it would be better to use the 12V because you also need it for the lock.

I did excaclty the same thing as you. I made an escape room puzzel with 3 RFID chips. If the right 3 tags are present, a 4-digit code is shown on a small LCD. I had to use a 3.3V regulators and write complicated code, but that was because of multiple chips not working even on USB. Your chips seem to be working fine though so you don't need that.

sjoerd1999 avatar Aug 22 '18 18:08 sjoerd1999

This code should work if your RFID chips are working fine.

/**
   -----------------------------------------------------------------------------------------
               MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
               Reader/PCD   Uno/101       Mega      Nano v3    Leonardo/Micro   Pro Micro
   Signal      Pin          Pin           Pin       Pin        Pin              Pin
   -----------------------------------------------------------------------------------------
   RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
   SPI SS 1    SDA(SS)      ** custom, take a unused pin, only HIGH/LOW required *
   SPI SS 2    SDA(SS)      ** custom, take a unused pin, only HIGH/LOW required *
   SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
   SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
   SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15

*/

#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN         9          // Configurable, see typical pin layout above

#define SS_1_PIN        6         // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 2 /3
#define SS_2_PIN        7          // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 1 / 3
#define SS_3_PIN        8          // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 1 / 2

#define NR_OF_READERS   3         // How many readers you have?

byte ssPins[] = {SS_1_PIN, SS_2_PIN, SS_3_PIN};

MFRC522 mfrc522[NR_OF_READERS];   // Create MFRC522 instance.

String currentIDs[] = {"00000000", "00000000", "00000000"}; // Current ID's, changes as you play
String correctIDs[] = {"53806d1d", "1692a012", "738811d"}; // Which ID's are correct? , stays constant as it checks this with the current ID's

void setup() {
  Serial.begin(9600); // Initialize serial communications with the PC
  SPI.begin();        // Init SPI bus
}

void loop() {
  for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
    currentIDs[reader] = "00000000";
    digitalWrite(reader + 2, HIGH);
    delay(40);
    mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN); // Init each MFRC522 card
    delay(40);
    if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial()) {
      currentIDs[reader] = getCode(mfrc522[reader].uid.uidByte, mfrc522[reader].uid.size);
      mfrc522[reader].PICC_HaltA();
      mfrc522[reader].PCD_StopCrypto1();
    }
    digitalWrite(reader + 2, LOW);
  }

  // Print out the current ID's
  Serial.print(currentIDs[0]);
  Serial.print(" , ");
  Serial.print(currentIDs[1]);
  Serial.print(" , ");
  Serial.println(currentIDs[2]);


  if (currentIDs[0] == correctIDs[0] && currentIDs[1] == correctIDs[1] && currentIDs[2] == correctIDs[2]) { // If all ID's are correct
    Serial.println("ALL 3 CORRECT, YOU WIN");
  }

}

String getCode(byte *buffer, byte bufferSize) {
  String code = "";
  for (byte i = 0; i < bufferSize; i++) code = code + String(buffer[i], HEX);
  return (code);
}

sjoerd1999 avatar Aug 22 '18 18:08 sjoerd1999

Has anyone ever tried using multiple MRFC522 RFID readers bought from china (I guess they are clones)? They work perfectly when using one only, but it looks like there is some noise on the MOSI line even if I turn off the readers that I do not want to read by actively pulling the corresponding SS pins high. The ReadUidMultiReader code works, when I disconnect all the MOSI cables exept from one, but of course that is just helpful for debugging. Or am I missing something else?

haaslukas avatar Sep 12 '18 14:09 haaslukas

Has anyone ever tried using multiple MRFC522 RFID readers bought from china (I guess they are clones)? They work perfectly when using one only, but it looks like there is some noise on the MOSI line even if I turn off the readers that I do not want to read by actively pulling the corresponding SS pins high. The ReadUidMultiReader code works, when I disconnect all the MOSI cables exept from one, but of course that is just helpful for debugging. Or am I missing something else?

Hi, please look at my posts above. I got chips from AliExpress that had this problem.

The only solution I found is: Turn chip 1 on, Read data chip 1, Turn chip 1 off. And repeating that for all sensors.

You are supposed to turn the chips on/off not with the SS pin, but with the 3.3V power input of the MFRC522. The readers need 3.3v, and the digital pins provide 5v. So I used a 3.3v regulator to convert the 5v to 3.3v. Otherwise the RFID readers might explode. I used the LD1117V33.

Please take a look at the code above.

After hours and hours of trying this is the best method I could find.

You can email me at [email protected] in case you still have questions or want more info.

sjoerd1999 avatar Sep 12 '18 15:09 sjoerd1999

Mine are from China too and maybe any problem to recognize some rfid tags but all work in the system. Now I have 6 readers working fine. I use an arduino Pro mini at 3.3v so I haven't to convert the supply voltage. I did a last change in the system, now the SS pin of all RC522 readers are fixed to be always on and use the RST pin to not only power off but turn it to low power consumption. When I do this, only one reader is on at the same time, no interferences an the fewer consumption possible. The system works for weeks with only three AA 2300mAh batteries, no regulator used.

MDLSoft avatar Sep 16 '18 07:09 MDLSoft

Since there's only one reader on at the same time, all chips could also use the same SS pin to save some pins. Don't know if that would work with the RST pin method though.

Using a 3.3V Arduino is smart! Only a bit annoying if you want to use the Arduino to run a 5V component as well.

Could you explain why you are using the RST pin to power it off? In my method I just cut the 3.3V line. Is the RST method better?

Normally the readers take 20mAh each, so when you're only running them one by one for a short period of time, this saves a huge amount of power indeed!

sjoerd1999 avatar Sep 16 '18 13:09 sjoerd1999

Of course, using RST pin you use the same SS pin for all readers. This is as I have configured. I suppose that cut the supply line or using the RST is the same, in both cases requires same initialization time. How did you that? The supply is directly one pin from arduino? For me using the RST pins was the most obvious and easy, one arduino pin to each RST, and shared SS pin. In my case each arduino's output haven't to support any current than internal pull-up but since only one reader working at time, no problem for the arduino. I desoldered all leds to reduce the consumption, not a drastic change but sure better durability of batteries.

I haven't any problem using 5v input modules supplying it with only 3.3v, or maybe only a simple transistor as digital switch when "power" inductance connected without optocoupler isolation.

MDLSoft avatar Sep 16 '18 14:09 MDLSoft

The Arduino digital pins can provide 20mAh, the same as the chips take. So yeah the supply is directly from the Arduino pin in my case. What code do you use to do the RST thing? digitalWrite(RSTpin, LOW) when sensing, digitalWrite(RSTpin, HIGH) when off?

sjoerd1999 avatar Sep 16 '18 14:09 sjoerd1999

Yes, the way as I use RST is as you said: digitalWrite(RSTpin, LOW) when sensing digitalWrite(RSTpin, HIGH) when off

I think our sketches should very similar because the concept of working is about the same.

MDLSoft avatar Sep 16 '18 16:09 MDLSoft