#include <SPI.h>
#include <MFRC522.h>
// Number of readers
#define NR_OF_READERS 5
// SS pins for each reader
const int ssPins[NR_OF_READERS] = {2, 3, 4, 5, 6};
const int rstPin = 9; // common RST pin
MFRC522 mfrc522[NR_OF_READERS]; // array of MFRC522 instances
void setup() {
Serial.begin(9600);
while (!Serial); // wait for Serial to initialize
SPI.begin(); // initialize SPI bus
for (uint8_t i = 0; i < NR_OF_READERS; i++) {
mfrc522[i].PCD_Init(ssPins[i], rstPin); // Init each MFRC522 reader
Serial.print(F("Reader "));
Serial.print(i);
Serial.println(F(" initialized."));
}
}
void loop() {
for (uint8_t i = 0; i < NR_OF_READERS; i++) {
// Look for new cards
if (mfrc522[i].PICC_IsNewCardPresent() && mfrc522[i].PICC_ReadCardSerial()) {
Serial.print(F("Reader "));
Serial.print(i);
Serial.print(F(": UID: "));
for (byte j = 0; j < mfrc522[i].uid.size; j++) {
Serial.print(mfrc522[i].uid.uidByte[j] < 0x10 ? " 0" : " ");
Serial.print(mfrc522[i].uid.uidByte[j], HEX);
}
Serial.println();
//mfrc522[i].PICC_HaltA(); // Stop reading
}
}
}