Working with RFID Technology
RFID (Radio Frequency Identification) is a wireless technology that uses radio waves to identify and track objects. You've probably encountered RFID without realizing it: apartment keys, office access cards, parking passes, contactless credit cards, hotel keycards, and toll passes all use RFID technology.
What We'll Build
In this section, we'll use the RC522 RFID Card Reader Module to read data from RFID tags and key fob tags. The RC522 operates at 13.56 MHz and typically comes with MIFARE Classic 1K cards that contain 1KB of memory.
RFID Categories by Frequency
- Low Frequency (LF): ~125 kHz, short range (up to 10cm), used in access control and livestock tracking
- High Frequency (HF): 13.56 MHz, range of 10cm to 1m, widely used in access control, payments, and ticketing (we'll use this one)
- Ultra-High Frequency (UHF): 860–960 MHz, range up to 12m, used in retail inventory and logistics
Active vs Passive RFID
RFID tags are powered in two different ways:
- Active tags: Have their own battery and can transmit signals independently. Used for tracking large objects over long distances.
- Passive tags: No battery required. They're powered by electromagnetic fields from the RFID reader. These are the most common type and what we'll use (RC522 module).
The RC522 Module
The RC522 RFID Card Reader Module is built on the MFRC522 IC designed by NXP. It's affordable, widely available, and perfect for learning. The module supports SPI, UART, and I2C communication protocols.
Module Specifications
| Operating Frequency | 13.56 MHz |
| Supported Standards | ISO/IEC 14443 A / MIFARE |
| Reading Distance | 0–50 mm |
| Operating Voltage | 3.3V (Do not use 5V!) |
| Current Draw | 13–26 mA (operating), 10–13 mA (idle) |
MIFARE Classic 1K Memory Structure
The MIFARE Classic 1K card is divided into 16 sectors, each containing 4 blocks of 16 bytes. This gives a total capacity of 1KB (16 sectors × 4 blocks × 16 bytes = 1024 bytes).
Important Memory Blocks
- Manufacturer Block: Block 0 of Sector 0 contains the UID and manufacturer data (read-only)
- Sector Trailer: Last block of each sector holds authentication keys (KeyA and KeyB) and access conditions
- Data Blocks: The remaining blocks store user data
Wiring the RC522 to Pico
We'll use SPI communication for this project. Connect the following pins:
| Pico Pin | RC522 Pin |
|---|---|
| 3.3V | 3.3V |
| GND | GND |
| GPIO 4 | MISO |
| GPIO 5 | SDA (CS) |
| GPIO 6 | SCK |
| GPIO 7 | MOSI |
Projects Covered
- Read UID: Read the unique identifier from RFID tags
- LED on Match: Turn on LED when specific tag is detected
- Read Data: Read data from specific blocks on the card
- Dump Memory: Read and display all memory sectors
- Write Data: Write custom data to RFID cards
⚠️ Important Safety Note
The RC522 module operates at 3.3V only. Using 5V will damage the module. Always double-check your power connections before turning on your circuit. When writing data, be careful not to overwrite sector trailer blocks, as this can make the sector permanently unusable.
Complete code examples using the mfrc522 crate with USB serial communication are available in the project repository. We'll use the rp-hal implementation to keep things straightforward.