Security is a big challenge in modern infrastructure, be it systems or properties. While passwords have played a key role in access control, they are no longer safe because bad actors can easily exploit them. One of the ways to improve security is by using RFID for access control. The system communicates wirelessly to compare unique IDs and requires the cardholder to be nearby. The RC522 module is a perfect example of this, and here's a close-up look at it to help you incorporate it into your project.
What is the RC522 RFID Reader/Writer Module?
The RC522 is an RFID (Radio Frequency Identification) module with an operating frequency range of 13.56 MHz. Based on the MFRC522 IC, the module supports UART, I2C, and SPI, and it usually comes with a critical fob tag (1KB memory) and an RFID card. The unit creates the 13.56 MHz electromagnetic field around it to communicate with other ISO 14443A standard tags at a maximum data rate of 10Mbps.
An RFID chip
RC522 RFID Module Pinout
The RC522 has eight pins with the following functions.
RC522 Specifications and Features
How to Interface RC522 RFID Module with Arduino?
The first step to interfacing the two is connecting the power and data pins. The data pins will differ depending on the Arduino microcontroller, so use the following table to guide you when using UNO, NANO, or MEGA.
The hardware SPI pins are quick, and we'll use them because the module requires fast data transfer speeds. We will not use the IRQ pin because the Arduino library in the description below does not support it.
As for the power supply, connect the module's Vcc and GND pins to the Arduino's 3.3V and ground, respectively.
Reading RFID Tag Code
First, download the MFRC522 RFID library, then install it in the Arduino IDE by going to Sketch > Include Library > Add. ZIP Library and picking the downloaded zip file. After installation, go to File > Examples > MFRC522 > DumpInfo.
This DumpInfo sketch does not write data to the tag. Instead, it only tells if you have read the tag, then displays information about it. Go to the beginning of the file and ensure you initialize the RST pin correctly, which is five in our case.
After that, upload the sketch code to Arduino and open the serial monitor to check the results. If you bring the tag closer to the module, you should get the following output.
Keep the tag close to the module until it displays all the results. While it may seem confusing, the output is straightforward. It shows the tag's UID (Unique Identification), memory size, and the entire 1K memory.
The 1K memory is like a 3D matrix that contains 16 sectors, each with four blocks, and each block can store 16 bytes of data. This combination results in a 1KB memory.
16 x 4 x 16 = 1024 bytes (1KB)
Writing RFID Tag Code
Before writing code, you need to know that the fourth block of each sector is known as the sector trailer and contains access bit information. Therefore, you can only use the first three blocks (0, 1, and 2), or 48 bytes per each 64-byte sector.
Also, the first block (block 0) of the first sector contains the UID and IC manufacturer data and is known as the Manufacturer block. Don't try to overwrite this block because it might lock the card permanently.
With that clarified, try out this sketch code to write data to the RFID tag.
The output should be as follows:
Scan a MIFARE Classic Card
2 is a data block:
block was written
block was read
read block: Test-OurPCB-Test
You can extend the system further by incorporating an LCD to build an RFID door-lock access control system. The setup should scan the unique ID of each RFID tag when close by, then compare it with a predefined value or master tag stored in the Arduino microcontroller. If the two values match, you will have access. Otherwise, it will be access denied and no entry.
RC522 vs. PN532: Make a Choice
Both modules are products of NXP Semiconductors, but the RC522 is a high-frequency radio chip supporting the ISO14443A protocol. The PN532 is a bit more advanced because it supports Near Field Communication (NFC) with a 50mm range. There are a few other differences, such as in the power supply, but the primary one is the addition of NFC support.
Therefore, if you want a versatile RFID module that supports the NFC protocol, such as for contactless payment using phones, go for the PN532. But if you only need the ISO14443A protocol for your project, pick the affordable RC522.
A phone with NFC for contactless payment
Other RFID Modules
- RFID tag
- PN532 RFID Module
- EM-18 RFID Reader
RC522 RFID Module Applications
- Automatic billing systems
- Attendance systems
- Access control systems
- Identification and verification systems
In conclusion, the RC522 is a relatively affordable RFID module. Despite this, it performs exceptionally well and has impressive features. If you have any questions, contact us for further clarification.