All RFID Product

RC522 Library,Everything You Need to Know for Arduino and ESP32 Projects

If you’ve ever played with RFID modules, chances are you’ve come across the RC522 library. The RC522 module uses the MFRC522 chip and is one of the most popular RFID readers for hobbyists. It’s small, cheap, and surprisingly versatile. With the right library, you can read and write RFID cards, track access, or integrate RFID into DIY projects. I’ve put together a full guide covering both the Arduino and ESP32 versions of the RC522 library, how it works, what it supports, and practical tips from real-world use.

What Is the RC522 Library?

In simple terms, the RC522 library is a set of code that lets your microcontroller talk to the RC522 RFID module. There are two main implementations people use:

  1. Arduino RC522 Library (Miguel Balboa)
    • Works via SPI on Arduino boards.
    • Reads and writes 13.56 MHz RFID cards, mainly MIFARE Classic 1K, 4K, and Mini.
    • Comes with examples for reading card UID, writing and reading data blocks, and authenticating sectors.
    • The library is stable and widely used, though development has mostly stopped; only small fixes are done.
  2. ESP-IDF RC522 Library (abobija)
    • Designed for ESP32 using the ESP-IDF framework.
    • Supports both SPI and I2C communication.
    • Fully supports MIFARE Classic cards, partially supports Ultralight and NTAG cards.
    • Provides card lifecycle events—card inserted, card removed.
    • Works well with ESP32 tasks and event-driven applications.

Both libraries make using RC522 modules simpler, no need to dive into low-level RFID protocol details. But they have differences, so choosing the right one depends on your setup.

How the RC522 Library Works

The RC522 module communicates with your microcontroller through SPI (Arduino) or SPI/I2C (ESP32). The workflow is straightforward:

  1. Initialize the module
    • Arduino: mfrc522.PCD_Init();
    • ESP32: rc522_init() or a similar initialization function.
  2. Check for new cards
    • Example (Arduino): if (!mfrc522.PICC_IsNewCardPresent()) return;
  3. Read the card UID and authenticate
    • UID is read using PICC_ReadCardSerial().
    • Authenticate using default or custom keys to access data blocks.
  4. Read or write card data
    • Use the library’s functions to read/write blocks or sectors.
    • Stop communication after operations to free the SPI/I2C bus.

This workflow lets you build access control systems, inventory trackers, or simple ID systems.

Features of the RC522 Library

Arduino RC522 Library

  • Read and write MIFARE Classic cards.
  • Retrieve card UID, read/write blocks, authenticate sectors.
  • Includes example programs like DumpInfo, ReadWrite, and UID detection.

ESP-IDF RC522 Library

  • Works with SPI and I2C on ESP32.
  • Provides card lifecycle events (inserted, removed).
  • Partial support for Ultralight and NTAG cards.
  • Event-driven, so you can react immediately to a card being presented or removed.

Limitations

  • No support for DESFire cards or AES-encrypted cards.
  • Uses Crypto1 encryption, which is not secure for sensitive applications.
  • Advanced NFC features like card emulation or peer-to-peer are not supported.
  • Multi-module setups need careful SPI/CS pin management.

Installation and Setup

Arduino Setup

  1. Install the library via Library Manager or download from GitHub.
  2. Connect the RC522 module: SDA → D10, RST → D9, SCK → D13, MOSI → D11, MISO → D12, 3.3V → 3.3V, GND → GND.
  3. Include the library: #include <MFRC522.h>.

ESP32 Setup

  1. Add the component in ESP-IDF: idf.py add-dependency "abobija/rc522"
  2. Set up GPIO pins for SDA, SCK, MOSI, MISO, and RST.
  3. Include the RC522 header and initialize the module.

Pro Tip: Always use 3.3V logic. Using 5V may permanently damage the RC522 module.

Applications

  • Access control: Employee ID, membership, or school attendance systems.
  • Inventory tracking: Tag products or boxes with RFID.
  • DIY projects: Smart door locks, interactive displays, hobby projects.
  • Learning: Great for beginners learning RFID, SPI/I2C, and microcontrollers.

Practical Notes from Experience

  • Module quality matters. Low-cost RC522 clones often have poor range or unstable reads.
  • Always test with a practice card before writing to production cards. Sector 0 and UID changes can permanently lock a card.
  • Arduino examples like DumpInfo or ReadWrite are the best starting points.
  • On ESP32, lifecycle events let you respond immediately when a card is presented or removed.
  • If your project requires security, avoid MIFARE Classic; Crypto1 is easily cracked. Consider DESFire or MIFARE Plus instead.
  • Multi-module setups require careful SPI bus and CS pin management. Otherwise, you’ll run into communication issues.

Conclusion

The RC522 library is reliable, practical, and widely used. For Arduino users, Miguel Balboa’s version is mature and stable. For ESP32, abobija’s ESP-IDF library works better with tasks and events. Both libraries simplify RFID reading and writing. While they’re not meant for high-security applications, they’re perfect for DIY projects, prototypes, and learning.

If you want to integrate RFID quickly and effectively, the RC522 library is the go-to solution—well-documented, supported by a community, and beginner-friendly.

CK-B5L Portable RFID Reader iPhone

CK-B5L Portable RFID Reader iPhone

2025-05-20

Cykeo CK-B5L portable RFID reader iPhone offers Bluetooth 5.0 connectivity, 500 tags/sec scanning, and IP54 ruggedness for retail/warehouse/medical asset tracking.

CK-RA12L 12dBi Long Range  RFID Reader

CK-RA12L 12dBi Long Range RFID Reader

2025-04-07

Cykeo CK-RA12L industrial Long Range RFID Reader delivers 20m read range, 200+ tags/sec scanning, and IP67 protection for manufacturing/logistics applications. Supports ISO 18000-6C/GB protocols.

CK-RA9L 9dBi Long Range RFID Tag Reader

CK-RA9L 9dBi Long Range RFID Tag Reader

2025-04-03

Cykeo CK-RA9L industrial long range rfid tag reader features 9dBi antenna, 500 tags/sec speed, IP67 metal housing for outdoor asset tracking in logistics/construction/automotive. Supports ISO 18000-6C/6B protocols.

CK-RA6L 6dBi UHF RFID Long Range Reader

CK-RA6L 6dBi UHF RFID Long Range Reader

2025-04-03

Cykeo’s CK-D6L industrial RFID long range reader features 20m read distance, 500 tags/sec speed, and IP67 protection. Ideal for warehouse automation, manufacturing WIP tracking, and smart logistics. Supports ISO 18000-6C/6B protocols.

CK-RA4L 4dBi Long Range RFID Reader

CK-RA4L 4dBi Long Range RFID Reader

2025-04-03

Cykeo’s industrial long range RFID reader delivers 20-meter scanning, 500+ tags/sec speed, and IP67 waterproof design for automated warehouses, logistics, and harsh environment applications.

CK-R16L 16-port UHF RFID Fixed Reader

CK-R16L 16-port UHF RFID Fixed Reader

2025-04-01

Cykeo CK-R16L UHF RFID fixed reader offers 16-channel scanning, 15m range, ISO 18000-6C compliance, and rugged design for smart lockers/warehouses. Integrates with WMS via TCP/IP.

CK-R8L 8-Port  Fixed RFID Reader

CK-R8L 8-Port  Fixed RFID Reader

2025-04-01

Cykeo’s CK-R8L UHF fixed RFID reader offers 8-antenna management, 20m range, and GB/T29768 compliance for automated logistics, manufacturing, and access control. Features Android 4.4, 33dBm power, and industrial I/O.

CK-R4L 4-Port Fixed UHF RFID Reader

CK-R4L 4-Port Fixed UHF RFID Reader

2025-04-01

Cykeo’s CK-R4L 4-port Fixed UHF RFID Reader delivers 400 tags/sec scanning, ISO 18000-6C compliance, and IP65 protection. Ideal for warehouse automation, manufacturing WIP tracking, and logistics management.

PgUp: PgDn:

Relevance

View more