Interfacing RC522 RFID Module With Arduino

by Rachana Jain in Circuits > Arduino

32 Views, 0 Favorites, 0 Comments

Interfacing RC522 RFID Module With Arduino

20250705_163913.jpg

In our everyday lives, we frequently encounter RFID (Radio Frequency Identification) systems, often without even noticing. One of the most commonly seen applications of this technology is the Electronic Toll Collection (ETC) system. In this setup, vehicles equipped with RFID tags can pass through toll booths without stopping. The RFID reader installed at the toll gate detects the tag, and the toll amount is automatically deducted from the user's prepaid account—making the process seamless, fast, and efficient.

Apart from ETC systems, RFID technology is widely used in various domains such as:

  1. Contactless payment cards for secure and quick transactions
  2. Inventory tracking and management in warehouses and retail stores
  3. Anti-theft detection systems in supermarkets
  4. Access control systems in buildings and offices

To explore RFID applications practically, we often use an RFID module with a microcontroller. Among the available RFID modules, the RC522 RFID reader/writer stands out as the most popular and affordable choice for Arduino-based projects.

In this comprehensive tutorial, we will learn what RFID technology is, how it works, and how to interface the RC522 RFID module with the Arduino UNO. You will also learn how to read and write data on RFID cards using Arduino.

What Is RFID Technology and How Does It Work?

RFID (Radio Frequency Identification) is a contactless technology used for automatic identification and data capture. It uses radio waves to transfer data between a reader and an RFID tag without the need for physical contact.

An RFID system comprises two essential components:

1. RFID Tag (or Transponder)

This is a small electronic device that is attached to the object you want to identify or track. The tag consists of:

  1. A microchip that stores data
  2. An antenna that communicates with the reader

There are two types of RFID tags:

  1. Passive Tags:These tags don’t have an internal power source. Instead, they draw power from the electromagnetic field generated by the reader’s antenna. They are cost-effective and widely used.
  2. Active Tags:These tags have an internal battery and can transmit signals over longer distances.

RFID tags are available in several form factors such as cards, key fobs, stickers, or embedded chips.

2. RFID Reader

The RFID reader is a device that emits radio waves and receives signals from nearby RFID tags. It performs the following tasks:

  1. Sends an electromagnetic signal through its antenna
  2. Powers the tag (if it's passive)
  3. Receives data transmitted by the tag
  4. Sends the data to a microcontroller or computer system for further processing

When a passive RFID tag comes within range of the reader’s electromagnetic field, the tag gets powered and responds by sending its stored data back to the reader. This method of communication is known as backscatter.

The reader decodes this signal and converts it into meaningful digital data, which can then be used for authentication, logging, inventory management, or other purposes.

What Is the RC522 RFID Module?

doc_pics.jpg

The RC522 RFID module is a widely-used and low-cost RFID reader/writer module based on the MFRC522 chip developed by NXP Semiconductors. It operates at a frequency of 13.56 MHz, which is the standard frequency for RFID communication.

This module is suitable for short-distance communication—typically within a 5 cm range—and supports multiple communication protocols including: SPI (Serial Peripheral Interface), and I2C (Inter-Integrated Circuit), UART (Universal Asynchronous Receiver-Transmitter)

Most RC522 modules come with:

  1. A MIFARE Classic 1K RFID card
  2. A key fob/tag

RC522 RFID Module Pinout

RC522 RFID Module Pinout.png


VCC: Provides power to the module (connect to 3.3V on Arduino)

RST (Reset): Used to reset the module programmatically

GND: Ground connection (connect to Arduino GND)

IRQ: Interrupt pin, can signal the microcontroller when a tag is nearby

MISO/SCL/TX: Multi-purpose pin depending on the protocol:

- MISO (SPI mode)

- SCL (I2C mode)

- TX (UART mode)

MOSI: Master-Out-Slave-In pin (used in SPI mode for sending data from Arduino to the module)

SCK: Serial Clock (used in SPI mode to synchronize data transfer)

SS/SDA/RX

Multi-purpose:

- SS (Slave Select in SPI mode)

- SDA (I2C mode)

- RX (UART mode)


⚠️ Important Note: The RC522 module operates at 3.3V. Connecting it directly to 5V may damage the module. Make sure to use proper voltage levels.

Interfacing an RC522 RFID Module to an Arduino

Slide1.PNG

The RC522 RFID module is capable of communicating through SPI, UART, or I2C protocols. However, in this tutorial, we will use the SPI protocol to establish communication between the Arduino UNO and the RFID reader. SPI is preferred for its high-speed data transfer and straightforward implementation.

To begin, we need to connect the necessary pins of the RC522 module to the Arduino UNO. The SS (Slave Select) pin of the RFID module should be connected to digital pin 10 on the Arduino. The SCK (Serial Clock) pin goes to digital pin 13, while the MOSI (Master Out Slave In) pin connects to digital pin 11. The MISO (Master In Slave Out) pin should be wired to digital pin 12. These four pins handle the main SPI communication between the RFID module and the Arduino.

Next, we connect the RST (Reset) pin of the RC522 module to digital pin 9 of the Arduino. This pin is used to reset the module during initialization. For power connections, the VCC pin of the module must be connected to the 3.3V pin on the Arduino, and the GND pin to the Arduino’s GND. It's important to note that the RC522 operates at a 3.3V logic level and should never be powered with 5V, as doing so can damage the module.

After wiring the RFID module, we can proceed to connect the I2C LCD display to the Arduino. Start by connecting the VCC and GND pins of the I2C LCD to the Arduino’s 5V and GND pins, respectively. Then, connect the SCL (Serial Clock) pin of the LCD to the SCL pin of the Arduino, and the SDA (Serial Data) pin of the LCD to the SDA pin of the Arduino. On the Arduino UNO, the SCL and SDA lines correspond to analog pins A5 and A4, respectively. These connections allow the Arduino to send and receive data from the LCD using just two communication lines. You might notice color-coded wires like pink and blue connected to the SCL and SDA pins of the LCD, which are internally routed to pins A5 and A4 on the Arduino.

With these connections completed, both the RC522 RFID reader and the I2C LCD display are properly interfaced with the Arduino and ready for coding and operation.

Arduino Code to Read All the Data of RFID Card

RFID Card.png

Upload the following code to your Arduino:

/*
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;
}
}
}


To learn more checkout Interfacing RC522 RFID Module with Arduino