Multiple RFID (RC522) in MEGA 2560

I’m new to Arduino and I’m trying to connect multiple RFID RC522 to an Arduino MEGA 2560. So far I’ve been able to connect 4 RFID and got them working, but when I connect the 5th it stops working as it should. Here’s how the code looks like:

#include <SPI.h>
#include <MFRC522.h>
#include <RFID.h>
RFID rfid(22, 8);
RFID rfid2(23, 7);
RFID rfid3(24, 6);
RFID rfid4(25, 5);
RFID rfid5(26, 4);

bool uno, dos, tres, cuatro, cinco;

void setup() {
  Serial.begin(9600);
  SPI.begin(); 
  rfid.init();
  rfid2.init();
  rfid3.init();
  rfid4.init();
  rfid5.init();
}

void loop() {
  uno =  false;
  dos = false;
  tres = false;
  cuatro = false;
  cinco = false;
  if (rfid.isCard()) {
    if (rfid.readCardSerial()) {
      String serial;
      for (int i = 0; i <= 4; i++) {
        serial += rfid.serNum[i];
      }
      if (serial == "xxx")
        uno = true;
      else if (serial == "yyy")
        dos = true;
      else if (serial == "zzz")
        tres = true;
      else if (serial == "aaa")
        cuatro = true;
      else if (serial == "bbb")
        cinco = true;
    }
  }
  rfid.halt();
  delay(50);

  if (rfid2.isCard()) {
    if (rfid2.readCardSerial()) {
      String serial;
      for (int i = 0; i <= 4; i++) {
        serial += rfid2.serNum[i];
      }
      if (serial == "xxx")
        uno = true;
      else if (serial == "yyy")
        dos = true;
      else if (serial == "zzz")
        tres = true;
      else if (serial == "aaa")
        cuatro = true;
      else if (serial == "bbb")
        cinco = true;
  }
  rfid2.halt();
  delay(50);

  if (rfid3.isCard()) {
    if (rfid3.readCardSerial()) {
      String serial;
      for (int i = 0; i <= 4; i++) {
        serial += rfid3.serNum[i];
      }
      if (serial == "xxx")
        uno = true;
      else if (serial == "yyy")
        dos = true;
      else if (serial == "zzz")
        tres = true;
      else if (serial == "aaa")
        cuatro = true;
      else if (serial == "bbb")
        cinco = true;
    }
  }
  rfid3.halt();
  delay(50);
  
  if (rfid4.isCard()) {
    if (rfid4.readCardSerial()) {
      String serial;
      for (int i = 0; i <= 4; i++) {
        serial += rfid4.serNum[i];
      }
      if (serial == "151244197219125")
      if (serial == "xxx")
        uno = true;
      else if (serial == "yyy")
        dos = true;
      else if (serial == "zzz")
        tres = true;
      else if (serial == "aaa")
        cuatro = true;
      else if (serial == "bbb")
        cinco = true;
    }
  }
  rfid4.halt();
  delay(50);

  if (rfid5.isCard()) {
    if (rfid5.readCardSerial()) {
      String serial;
      for (int i = 0; i <= 4; i++) {
        serial += rfid5.serNum[i];
      }
      if (serial == "xxx")
        uno = true;
      else if (serial == "yyy")
        dos = true;
      else if (serial == "zzz")
        tres = true;
      else if (serial == "aaa")
        cuatro = true;
      else if (serial == "bbb")
        cinco = true;
    }
  }
  rfid5.halt();
  delay(50);
  
  if (uno)
    Serial.print("uno;");
  if (dos)
    Serial.print("dos;");
  if (tres)
    Serial.print("tres;");
  if (cuatro)
    Serial.print("cuatro;");
  if (cinco)
    Serial.print("cinco;");
  Serial.print("\n");
  delay(200);
}

(I know I can make it better, I’m just doing tests)

I’m new to this, so I’m not really sure how to wire the RFIDs, the way I did it is attached. Basically I connected the SCK, MISO and MOSI from all RFID to the corresponding pins in de the Arduino MEGA, and the RST and SDA to individual pins. The GND and 3.3V are connected to an external power supply.

I guess I did something wrong, can someone tell me what it is?

Dazuma; I know my reply is late but I am going to try your example and report on ways to improve SPI bus performance using pull-up resistors at the transmission end points. I will attempt 10K at SC, MOSI, SS pins at the module side, using 5V separate as VCC. I will also see if using MISO pullup at MEGA pin input will work to improve signals I have high speed capture Oscilloscopes and other equipment to observe the effects. My own objectives are using four 522 module in SPI bus but later extending transmission distance using differential cabling method like RS-422B. I hope to come back soon. John