DEV Community

Cover image for Interfacing RC522 RFID Module with Arduino UNO
Play with Circuit
Play with Circuit

Posted on

Interfacing RC522 RFID Module with Arduino UNO

RFID, or Radio Frequency Identification, is a wireless technology used to identify objects without requiring direct physical contact. RFID systems are already part of many everyday applications. Electronic Toll Collection (ETC) is one common example, where vehicles equipped with RFID tags can pass through toll points without stopping and the toll amount can be automatically deducted. RFID is also widely used in contactless payment cards, warehouse inventory management, access-control systems, and anti-theft systems.

The RC522 is a popular and low-cost RFID reader/writer module that can be easily interfaced with microcontrollers such as the Arduino UNO. In this project, the RC522 is connected to an Arduino UNO using the SPI communication interface. A 16×2 I2C LCD is also used to display the unique identification number (UID) of a detected RFID card.

RFID Technology and Working Principle

RFID is a wireless communication technology that uses radio waves to automatically identify objects or devices. A basic RFID system consists of two main components: an RFID tag and an RFID reader.

An RFID tag contains an electronic chip and an antenna. The chip stores identification information and, depending on the type of tag, can also store additional data such as a serial number or other application-specific information. RFID tags can be either passive or active. Passive RFID tags obtain the energy required for communication from the electromagnetic field generated by the reader, while active RFID tags use their own battery. Passive tags are commonly available in the form of cards, key fobs, stickers, and other compact tags.

The RFID reader generates and receives radio-frequency signals and communicates with the RFID tag. Depending on the application, the reader can be implemented as a fixed or portable device. Both the reader and tag use antennas designed for their respective operating frequency.

When a passive RFID tag is placed near the reader, the reader generates an electromagnetic field through its antenna. This field activates the tag, allowing it to respond with its stored information. The tag sends the information back to the reader through radio communication, commonly referred to as backscatter communication. The reader receives and processes this information before passing the resulting data to a microcontroller or computer.

RC522 RFID Module

The RC522 is a compact RFID reader/writer module based on the MFRC522 RFID reader IC from NXP Semiconductors. It is designed for 13.56 MHz high-frequency RFID applications and has a typical operating range of up to approximately 5 cm.

The module supports multiple communication interfaces, including SPI, I2C, and UART, allowing it to be connected to different microcontrollers and development boards. Typical RC522 module kits are supplied with an RFID card and a key-fob tag.

The RC522 works with high-frequency RFID cards that comply with the ISO/IEC 14443 Type A standard.

The main specifications of the module include a 13.56 MHz operating frequency, a supply voltage of 2.5 V to 3.3 V, a maximum operating current of approximately 13–26 mA, and a typical reader range of around 5 cm. The available communication interfaces are SPI, I2C, and UART.

RC522 Hardware Overview

The RC522 module uses the MFRC522 RFID chip from NXP Semiconductors. The module includes an onboard 27.12 MHz crystal oscillator that provides the clock required by the RFID IC. It also includes an EMI filter and matching circuit to improve signal integrity and reduce electromagnetic interference.

A PCB antenna is integrated into the module and is used to generate and receive the electromagnetic field required for communication with RFID cards and tags.

RC522 Pinout

The RC522 module has eight pins. Some of these pins have different functions depending on the communication interface selected.

The VCC pin supplies power to the module. The RC522 requires a supply voltage between 2.5 V and 3.3 V, and for this project it is connected to the 3.3 V output of the Arduino UNO.

The RST pin is the reset input and is used to reset the RFID module during initialization or when required by the application.

The GND pin is the common ground connection and must be connected to the Arduino UNO GND.

The IRQ pin is an interrupt output that can be used to alert the microcontroller when an RFID event occurs. It is not required for the basic SPI-based interface used in this project.

The MISO/SCL/TX pin has different functions depending on the selected communication protocol. In SPI mode, it acts as MISO (Master-In-Slave-Out) and transfers data from the RC522 to the microcontroller. In I2C mode, the same pin functions as SCL, while in UART mode it functions as TX.

The MOSI pin stands for Master-Out-Slave-In. In SPI communication, it is used by the Arduino to send data to the RC522 module.

The SCK pin is the Serial Clock input. It receives clock pulses generated by the SPI master, which in this project is the Arduino UNO.

The SS/SDA/RX pin also has multiple functions. In SPI mode, it acts as the SS (Slave Select) signal used to select the RC522 device. In I2C mode, it functions as SDA, while in UART mode it acts as RX.

RFID Cards Supported by RC522

The RC522 is designed for 13.56 MHz high-frequency RFID cards that comply with the ISO/IEC 14443 Type A standard. Common card types used with the module include MIFARE Classic 1K, MIFARE Classic 4K, MIFARE Mini, and MIFARE Ultralight.

MIFARE Classic 1K provides 1 KB of memory organized into 16 sectors, with each sector containing four blocks. MIFARE Classic 4K provides 4 KB of storage and uses a sector-based memory structure. MIFARE Mini provides 320 bytes of memory, while MIFARE Ultralight provides 64 bytes and is designed as a lower-cost RFID card with limited write cycles.

MIFARE Classic 1K Memory Organization

This project uses a MIFARE Classic 1K RFID card. Understanding its memory structure is important when reading or writing data because some memory blocks are reserved for manufacturer information and access-control information.

The MIFARE Classic 1K memory is divided into 16 sectors, numbered from 0 to 15. Each sector contains four blocks, numbered from 0 to 3. Therefore, the complete card contains 16 × 4 = 64 blocks.

Each block can store 16 bytes of data. The total memory is therefore 64 × 16 = 1024 bytes, which corresponds to 1 KB.

Block 0 of Sector 0 is called the manufacturer block. It contains manufacturer information and the card UID and is read-only, so it should not be used for normal user data.

The last block of each sector is called the sector trailer. It contains Key A, Key B, and access bits that control access to the other blocks in that sector. Because these blocks are reserved, they cannot be treated as normal user storage.

There are 17 reserved blocks in total, giving 17 × 16 = 272 bytes of unusable memory. Therefore, the remaining user-accessible memory is 1024 − 272 = 752 bytes, corresponding to 47 blocks.

Interfacing RC522 with Arduino UNO

The RC522 can communicate with a microcontroller through SPI, UART, or I2C. In this project, SPI is used because it provides a straightforward way to communicate with the RFID reader using the Arduino UNO's hardware SPI pins.

The RC522 SS pin is connected to Arduino digital pin 10. The SCK pin is connected to digital pin 13, MOSI is connected to digital pin 11, and MISO is connected to digital pin 12. The RST pin is connected to digital pin 9 so that the Arduino can reset the RFID module during initialization.

The RC522 VCC pin is connected to the Arduino UNO's 3.3 V output, while the GND pin is connected to Arduino GND. The RC522 should not be powered from the Arduino's 5 V supply because the module operates at a 3.3 V supply and logic level.

The complete RC522-to-Arduino UNO connection is:

RC522 Pin Arduino UNO Pin
SS (Pin 1) Digital 10
SCK (Pin 2) Digital 13
MOSI (Pin 3) Digital 11
MISO (Pin 4) Digital 12
IRQ (Pin 5) Not Connected
GND (Pin 6) GND
RST (Pin 7) Digital 9
VCC (Pin 8) 3.3 V

Connecting the I2C LCD

A 16×2 I2C LCD is used to display the RFID card UID. The I2C interface on the Arduino UNO uses analog pins A4 and A5 as the SDA and SCL lines respectively.

Connect the LCD VCC and GND pins to the corresponding Arduino power pins. Connect SDA to A4 and SCL to A5.

The LCD connections are:

LCD Pin Arduino UNO
GND GND
VCC 5 V
SDA A4
SCL A5

The I2C LCD used in this project is configured with the address 0x27. The A0, A1, and A2 address-selection jumpers on the I2C backpack should remain unshorted for this configuration.

The basic communication path in this project is therefore:

RFID Card → RC522 → SPI → Arduino UNO → I2C → LCD

Software Requirements

The project uses Arduino IDE for programming the Arduino UNO. The source project uses Arduino IDE version 2.3.4 or later.

Two libraries are required. The MFRC522 library by GithubCommunity, version 1.4.12, provides the functions required to communicate with the RC522 RFID reader. The LiquidCrystal_I2C library by Frank de Brabander, version 1.1.2, is used to control the 16×2 I2C LCD.

Project Operation

After the RC522 and LCD are connected to the Arduino UNO, the Arduino initializes the RFID reader and I2C LCD. When an RFID card is placed near the RC522 antenna, the reader detects the card and communicates its information to the Arduino through SPI.

The Arduino can then retrieve the card UID and display it on the 16×2 I2C LCD. The same setup can be extended to read and write data to compatible MIFARE cards, provided the required authentication and memory-block rules are followed.

The project provides a simple foundation for experimenting with RFID-based identification and can be extended into applications such as RFID access control, attendance systems, electronic locks, inventory tracking, and other automation projects.

Important Hardware Notes

The RC522 must be supplied from a 3.3 V source. Do not connect its VCC pin directly to the Arduino UNO's 5 V supply.

The Arduino UNO's hardware SPI pins used in this project are D10 for SS, D11 for MOSI, D12 for MISO, and D13 for SCK. The RC522 reset line is connected to D9.

For the I2C LCD, the Arduino UNO uses A4 for SDA and A5 for SCL. The LCD in this project uses the 0x27 I2C address, with the A0, A1, and A2 address jumpers left unshorted.

This hardware arrangement allows the Arduino UNO to communicate with the RC522 RFID reader over SPI while simultaneously controlling the LCD through I2C.

For source code checkout: https://playwithcircuit.com/interfacing-rc522-rfid-module-with-arduino/

Top comments (0)