RFID technology has quietly become a part of our everyday life. From automated toll collection to contactless payment cards and inventory management in large warehouses, RFID systems provide fast and reliable object identification without physical contact. To experiment with this technology at the hobbyist or learning level, one of the most commonly used modules is the RC522 RFID reader/writer. It is inexpensive, compact, and easy to interface with microcontrollers like the Arduino UNO.
Understanding the RC522 ModuleThe RC522 is built around NXP’s MFRC522 IC, which is designed for 13.56 MHz RFID applications. The module can communicate over SPI, I²C, or UART, but with Arduino UNO, the SPI protocol is usually preferred because of its speed and ease of use. Its effective reading distance is up to 5 cm, making it suitable for short-range applications such as access control or simple automation projects.
The hardware includes a 27.12 MHz crystal oscillator that clocks the IC, along with an onboard EMI filter and matching circuit to ensure stable communication by reducing interference. A flat PCB antenna coil is also integrated on the module, which enables the wireless link between the reader and the RFID tags.
The RC522 comes with eight pins, each having a specific role depending on the communication interface used:
- VCC – The power supply pin. It must be powered with 3.3 V only. Supplying 5 V can damage the module.
- RST – Reset pin, used to initialize or reset the module during operation
- GND – Ground reference, to be connected with Arduino’s GND.
- IRQ – Interrupt pin, optional, used to signal the microcontroller when a tag is detected.
- MISO – Master-In-Slave-Out, used in SPI mode to send data from the RC522 back to the Arduino.
- MOSI – Master-Out-Slave-In, used in SPI mode to send data from Arduino to the module.
- SCK – Serial clock, generated by the Arduino to synchronize communication.
- SS (also labeled SDA/RX) – In SPI mode, this acts as the Slave Select pin to enable communication with the module.
When connecting the RC522 to the Arduino UNO using SPI, the process is straightforward but must be done carefully since the module works on 3.3 V logic. Begin by powering the module: connect the VCC pin of RC522 to the 3.3 V output of the Arduino UNO, and its GND to Arduino GND. This ensures the module operates at safe voltage levels.
Next, connect the communication lines. The SS pin of the module goes to Arduino digital pin 10, while the SCK pin connects to pin 13. For data transfer, link the MOSI pin of RC522 to pin 11 of Arduino, and the MISO pin to pin 12. To allow the Arduino to reset the module when required, connect the RST pin to digital pin 9. The IRQ pin is optional for basic projects and can remain unconnected. Now we connect a 16×2 I²C LCD to display the scanned RFID card’s UID. The I²C LCD has only four pins, making the wiring very simple. Connect its VCC to Arduino’s 5 V pin and GND to Arduino GND. The communication pins, SDA and SCL, connect to A4 and A5 of the UNO respectively. This allows the Arduino to print the UID directly on the LCD whenever a card is scanned.
Arduino Code to read all the Data of RFID Card /*
Code to Read all data from RFID card and send it to UART port @ baudrate 115200,n,8,1
by platwithcircuit.com
*/
#include <LiquidCrystal_I2C.h>
// Library to run I2C LCD
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
// this flag is used to check if previous card is removed or not
bool boIsPreviousCardRemoved = true;
void setup() {
// initialize the LCD
lcd.init();
// Turn ON the Backlight
lcd.backlight();
// Clear the display buffer
lcd.clear();
// Print a message to the LCD
lcd.setCursor(0, 0);
lcd.print("Initializing");
// Initialize serial communications with the PC
Serial.begin(115200);
while (!Serial); // Do nothing if no serial port is opened
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
delay(4); // Optional delay of 4 ms
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 i.e., RF Card Reader details
Serial.println(F("Scan PICC to see UID, SAK, type, and data in the Card"));
delay(1000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Place Card on");
lcd.setCursor(0, 1);
lcd.print("Card Reader");
}
void loop() {
// Make sure that previous card is removed before going ahead
if ((mfrc522.PICC_IsNewCardPresent() == true) && (boIsPreviousCardRemoved == true)) {
// Read Serial Data
if (mfrc522.PICC_ReadCardSerial() == true) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Card Detected");
lcd.setCursor(0, 1);
lcd.print("Keep it there...");
// Dump debug info about the card; PICC_HaltA() is automatically called
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
delay(1000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Remove Card From");
lcd.setCursor(0, 1);
lcd.print("Card Reader ");
boIsPreviousCardRemoved = false;
delay(2000);
}
} else {
if (boIsPreviousCardRemoved == false) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Place Card on");
lcd.setCursor(0, 1);
lcd.print("Card Reader");
boIsPreviousCardRemoved = true;
}
}
}
OutputTo learn how to Read/Write Data on RFID Card checkout: Interfacing RC522 RFID Module with Arduino
Comments