RFID (Radio Frequency Identification) technology enables automatic identification of objects and people via tags that transmit a unique UID when brought near a reader. This article shows how to connect the RC522 RFID reader to an M-Duino PLC, read the tag UID, and compare it against a list of authorised users using the Arduino IDE.
What you need
- M-Duino PLC
- Power supply
- RC522 RFID reader module
- RFID tags or cards
Connecting the RC522 to the M-Duino PLC
The RC522 communicates over SPI and has 8 pins, but the IRQ pin is not used in this example. Connect the remaining 7 pins as follows:
| RC522 | M-Duino PLC |
|---|---|
| 3.3V | 3.3V |
| RST | Pin 3 |
| GND | GND |
| IRQ | Not connected |
| MISO | 50 (SO) |
| MOSI | 51 (SI) |
| SCK | 52 (SCK) |
| SDA | Pin 2 |
The M-Duino has hardware switches behind its digital I/O pins. Make sure the switches for Pin 2 and Pin 3 are enabled before uploading the sketch.
Installing the MFRC522 library
Open the Arduino IDE, go to Tools > Manage Libraries (Ctrl+Shift+I), search for "MFRC522" and install the library by Miguel Balboa. Also install the Industrial Shields boards package for your M-Duino model:
How to install Industrial Shields boards in the Arduino IDE
Select your board under Tools > Board > Industrial Shields boards > M-Duino family and your model under Tools > Model.
Arduino sketch for RFID tag reading and comparison
The sketch below detects any RFID tag near the reader and prints its UID to the serial monitor. It then compares the UID against a stored array of users. If the UIDs match, access is granted; otherwise it is denied.
Before using the sketch you need to find the UID of your own RFID tag: upload the sketch, pass your tag over the reader, and note the UID printed in the serial monitor. Replace the bytes in the User1 array with your tag UID.
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 3
#define SS_PIN 2
MFRC522 mfrc522(SS_PIN, RST_PIN);
byte ActualUID[4];
byte User1[4] = {0x31, 0x31, 0x31, 0x31}; // Replace with your tag UID
void setup() {
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
Serial.println("Reading UID");
}
void loop() {
if (mfrc522.PICC_IsNewCardPresent()) {
if (mfrc522.PICC_ReadCardSerial()) {
Serial.print("Card UID:");
for (byte i = 0; i < mfrc522.uid.size; i++) {
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
ActualUID[i] = mfrc522.uid.uidByte[i];
}
if (compareArray(ActualUID, User1)) Serial.println(" Access granted");
else Serial.println(" Access denied");
mfrc522.PICC_HaltA();
}
}
}
boolean compareArray(byte array1[], byte array2[]) {
for (byte i = 0; i < mfrc522.uid.size; i++) {
if (array1[i] != array2[i]) return false;
}
return true;
}Expanding the access list
To support more users, add additional byte arrays (User2, User3, etc.) and add a comparison for each one inside the loop. For large numbers of tags, storing the UIDs on an SD card is a practical alternative to hardcoding them in the sketch.

Detecting RFID tags with the RC522 reader and M-Duino PLC