MFRC522 13.56MHz RFID Reader & Access Control
Read contactless 13.56MHz MIFARE cards and key fobs over hardware SPI to build a UID-verified access controller.
Explore contactless radio-frequency identification with the MFRC522 reader module. Wire the 3.3V SPI bus carefully to Arduino Uno, inspect unique card UIDs in hexadecimal, authorize trusted tags in firmware, and drive Granted/Denied status indicators.
Key Learning Objectives & Robotics Concepts
By building and programming this project, you will master the following core engineering skills:
Power Architecture & Voltage Staging
5V / 3.3V Regulated PowerThe MFRC522 operates strictly at 3.3V DC (drawing up to 26mA during 13.56MHz antenna excitation). Connect VCC exclusively to the Arduino Uno 3.3V pin—never 5V. CRITICAL: Power MFRC522 strictly from 3.3V—connecting VCC to 5V permanently destroys the RF transceiver IC!
Bill of Materials (BOM) & Hardware Components
| Component | Specifications & Alternative | Qty | Approx Cost |
|---|---|---|---|
| Arduino Uno R3 | ATmega328P hardware SPI controller | 1 | $8.00 |
| MFRC522 RFID Reader Module + Tags | 13.56MHz ISO14443A SPI module + card & keyfob | 1 | $3.50 |
| Green & Red 5mm LEDs + 220Ω Resistors | Access Granted / Denied visual indicators | 2 | $0.30 |
| Breadboard & Jumper Wires | 10× Male-to-Female / Male-to-Male jumpers | 1 | $2.00 |
Electrical & System Architecture
Wire RC522 VCC to 3.3V, GND to GND, RST to D9, SDA(SS) to D10, MOSI to D11, MISO to D12, and SCK to D13. Optional Green/Red status LEDs connect to D6 and D7 via 220Ω resistors.
Autonomous Behavior & Finite State Machine (FSM)
Deterministic Arduino loop handling RC522 13.56MHz SPI RFID Reader + Cards acquisition, filtering, and real-time output updates.
Step-by-Step Physical Assembly & Wiring Tutorial
Follow each of the 5 sequential milestone stages with technical photos, wiring checks, and pre-flight tests.
Double-Check 3.3V Power Pin First
Verify the 3.3V header on the Arduino Uno before wiring anything to the RC522 module.
- Solder header pins cleanly onto the RC522 PCB if they came loose.
- Locate the 3.3V pin on Arduino Uno (next to RESET and 5V).
- Never connect RC522 VCC to the 5V pin.
Wire SPI Bus & Status LEDs
Connect all 7 active RC522 pins (IRQ stays unconnected) and wire Green/Red LEDs to D6/D7.
- Wire 3.3V→3.3V, GND→GND, RST→D9, SDA(SS)→D10.
- Wire MOSI→D11, MISO→D12, SCK→D13; leave IRQ unconnected.
- Wire Green LED (+220Ω) to D6 and Red LED (+220Ω) to D7.
Install MFRC522 Library
Install the "MFRC522" library by GithubCommunity via Arduino Library Manager.
- Open Library Manager and search "MFRC522".
- Install the standard MFRC522 library by GithubCommunity.
- Run the Firmware Version diagnostic sketch to verify SPI communication.
Capture Your Card UID & Update Whitelist
Scan your white card or blue key fob, copy its hex UID, and paste it into AUTHORIZED_UID.
- Upload the production sketch and open Serial Monitor at 115200 baud.
- Tap the blue fob on the RC522 antenna coil and note the printed UID (e.g., A1 B2 C3 D4).
- Replace AUTHORIZED_UID in the code with your card's exact hex string and re-upload.
Test Authorized vs. Unauthorized Tags
Confirm your registered tag lights the Green LED while unregistered tags trigger Red.
- Tap the whitelisted key fob → Green LED (D6) lights for 1.5 seconds.
- Tap the unregistered white card → Red LED (D7) flashes Denied.
- Verify clean range (~2–4cm above the copper spiral antenna).
Subsystem Benchtop Verification Scripts
Test each hardware subsystem independently before deploying the full autonomous firmware.
1Bench Diagnostic: RC522 13.56MHz SPI RFID Reader + Cards Hardware Check
Subsystem DiagnosticMinimal standalone sketch to verify pin wiring and signal response for RC522 13.56MHz SPI RFID Reader + Cards before running the full project firmware.
// Diagnostic: Verify RC522 SPI Link & Firmware Version
#include <SPI.h>
#include <MFRC522.h>
MFRC522 rfid(10, 9);
void setup() {
Serial.begin(115200); SPI.begin(); rfid.PCD_Init();
rfid.PCD_DumpVersionToSerial();
}
void loop() {}Complete Production Firmware
Full working C++ source code with pin mappings, non-blocking timers, and FSM avoidance routines.
/**
* Project 9: MFRC522 13.56MHz RFID Access Controller
* Board: Arduino Uno R3 | SPI: SS=D10, RST=D9, MOSI=D11, MISO=D12, SCK=D13
* Library: MFRC522 by GithubCommunity
*/
#include <SPI.h>
#include <MFRC522.h>
const uint8_t SS_PIN = 10;
const uint8_t RST_PIN = 9;
const uint8_t LED_GRANTED = 6;
const uint8_t LED_DENIED = 7;
// Replace with your own card UID printed on first scan
const char* AUTHORIZED_UID = "A1 B2 C3 D4";
MFRC522 rfid(SS_PIN, RST_PIN);
String formatUid() {
String out = "";
for (byte i = 0; i < rfid.uid.size; i++) {
if (rfid.uid.uidByte[i] < 0x10) out += "0";
out += String(rfid.uid.uidByte[i], HEX);
if (i < rfid.uid.size - 1) out += " ";
}
out.toUpperCase();
return out;
}
void setup() {
Serial.begin(115200);
pinMode(LED_GRANTED, OUTPUT);
pinMode(LED_DENIED, OUTPUT);
SPI.begin();
rfid.PCD_Init();
Serial.println(F("RFID Access Controller Ready. Tap 13.56MHz card..."));
}
void loop() {
if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) return;
String scanned = formatUid();
Serial.print(F("Scanned UID: "));
Serial.println(scanned);
if (scanned == AUTHORIZED_UID) {
Serial.println(F("=> ACCESS GRANTED"));
digitalWrite(LED_GRANTED, HIGH);
delay(1500);
digitalWrite(LED_GRANTED, LOW);
} else {
Serial.println(F("=> ACCESS DENIED"));
for (int i = 0; i < 3; i++) {
digitalWrite(LED_DENIED, HIGH); delay(150);
digitalWrite(LED_DENIED, LOW); delay(150);
}
}
rfid.PICC_HaltA();
rfid.PCD_StopCrypto1();
}Firmware Architecture Explanation:
- Initializes hardware SPI at default safe clock speed and polls for ISO14443A transponders.
- Formats variable-length UID bytes into uppercase zero-padded hexadecimal strings for clear comparison.
- Properly halts card crypto state (PICC_HaltA + PCD_StopCrypto1) to prevent duplicate reads.
Operational Verification & Pin State Matrix
Input Signal vs. System Output Truth Table:
| Input / State | Pin / Signal | Detected Condition | Expected Output |
|---|---|---|---|
| UID == Whitelist | SPI Read OK | Authorized Keycard | Green LED (D6) ON 1.5s |
| UID != Whitelist | SPI Read OK | Unknown Card | Red LED (D7) 3× Rapid Blink |
Engineering Troubleshooting Matrix
| Problem | Likely Cause | Diagnostic Check | Engineering Solution |
|---|---|---|---|
| Version check returns 0x00 or 0xFF | Loose SPI jumper or cold solder joint on RC522 header | Inspect D10–D13, RST(D9), and 3.3V voltage | Re-seat all SPI leads and verify header pins are soldered cleanly. |
| Version reads OK but card never detects | Using a 125kHz RFID tag instead of 13.56MHz MIFARE tag | Test with the bundled blue fob / white card | Ensure tags are 13.56MHz ISO14443A compatible. |
| Module gets hot immediately | Connected to 5V instead of 3.3V | Unplug USB and inspect VCC wire | Move VCC strictly to 3.3V (damaged units must be replaced). |
Engineering Challenges & Upgrades
Take your build to the next level with these progressive engineering upgrades:
Store 3 authorized UIDs with user names and greet each user by name over Serial.
Unlock an SG90 servo deadbolt and display "Welcome" on an SSD1306 OLED on valid scan.
Scan a master admin card to temporarily register a new guest fob in EEPROM.