MFRC522 RFID Card Reader
MFRC522 RFID Card Reader
Overview
MFRC522 is a 13.56MHz RFID card reader module that communicates via SPI bus, supporting reading UIDs of Mifare S50/S70 and other IC cards. Suitable for access control systems, attendance tracking, identity recognition, and other scenarios.
Firmware Requirement: Standard / Full firmware enables
FASTBEE_ENABLE_RFIDby default; Lite has it disabled by default.
Supported Peripheral Types
| Type | type Value | Description |
|---|---|---|
| SENSOR | 38 | SPI sensor (MFRC522) |
Event Numbers
| Event | Number | Description |
|---|---|---|
| EVENT_RFID_CARD_DETECTED | 120 | New card detected |
| EVENT_RFID_CARD_REMOVED | 121 | Card removed |
Hardware Wiring
| MFRC522 Pin | ESP32 GPIO | Description |
|---|---|---|
| SDA (SS) | GPIO 5 | SPI chip select |
| SCK | GPIO 18 | SPI clock |
| MOSI | GPIO 23 | SPI master out slave in |
| MISO | GPIO 19 | SPI master in slave out |
| RST | GPIO 4 | Reset pin |
| VCC | 3.3V | Power supply |
| GND | GND | Ground |
MFRC522 operates at 3.3V; do not connect 5V!
Configuration
Method 1: Web Interface Configuration (Recommended)
Before saving MFRC522 configuration, verify SPI pins, chip select pin, reset pin, and 3.3V power supply.
Step 1: Navigate to Peripheral Management Page
- Open a browser and navigate to the ESP32 IP address
- After logging in, click Peripheral Configuration in the left menu
Step 2: Add RFID Card Reader Peripheral
Click the Add Peripheral button
Fill in the configuration:
Field Value Description Peripheral ID rfid1Unique identifier Name RFID Card ReaderDisplay name Peripheral Type Generic Sensor (type: 38) RFID driver SS Pin 5SPI chip select RST Pin 4Reset pin Driver Name MFRC522Fixed value Detection Interval 500500ms (200-500) Click Save
Step 3: Verify Configuration
- Find the newly added peripheral in the peripheral list
- Click the Enable toggle
- Swipe a card and check the reported UID
⚠️ Important: MFRC522 must use 3.3V power supply; 5V will damage the module; firmware must enable
FASTBEE_ENABLE_RFID=1.
Method 2: JSON Configuration File Import
Add the following configuration to the peripherals array in data/config/peripherals.json:
{
"id": "rfid1",
"name": "RFID Card Reader",
"type": 38,
"enabled": false,
"pins": [5, 4],
"params": {
"driver": "MFRC522",
"ssPin": 5,
"rstPin": 4,
"interval": 500
}
}Parameter Description
| Parameter | Description |
|---|---|
| driver | Driver name, fixed to "MFRC522" |
| ssPin | SPI chip select pin (consistent with pins[0]) |
| rstPin | Reset pin (consistent with pins[1]) |
| interval | Polling detection interval (ms), recommend 200-500 |
SPI bus pins (SCK/MOSI/MISO) use ESP32 default SPI pins; no need to specify in configuration.
Data Report Format
When a card is detected, UID is reported via MQTT:
[{"id": "rfid1", "value": "uid:A1B2C3D4"}]When card is removed:
[{"id": "rfid1", "value": "uid:removed"}]Event Trigger Mechanism
When the RFID module detects a card, it triggers system events:
EVENT_RFID_CARD_DETECTED(120): New card brought nearEVENT_RFID_CARD_REMOVED(121): Card removed
These events can be used as trigger conditions in periph_exec rules.
Peripheral Execution Integration
Web Interface Configuration Steps
Create Card Swipe Door Open Rule
- Switch to the Peripheral Execution Management tab
- Click the Add Rule button
- Configure event trigger:
- Trigger Type: Event Trigger
- Event Source: rfid1
- Event Number: 120 (card detected)
- Add actions:
- Action 1: Servo door open
- Action Type: Set PWM
- Target Peripheral: servo1
- Action Value: 180
- Action 2: Delay 3 seconds
- Action Type: Delay
- Delay Value: 3000 (milliseconds)
- Action 3: Servo door close
- Action Type: Set PWM
- Target Peripheral: servo1
- Action Value: 0
- Action 1: Servo door open
- Click Save
💡 Tip: Can use event 120 (card swipe) and 121 (card removed)
JSON Configuration Example
Card Swipe Door Open
{
"name": "Card Swipe Door Open",
"enabled": true,
"triggers": [
{
"type": "event",
"params": {
"periphId": "rfid1",
"eventCode": 120
}
}
],
"actions": [
{
"type": "servo_write",
"params": {
"periphId": "servo1",
"value": "180"
}
},
{ "type": "delay", "params": { "ms": 3000 } },
{
"type": "servo_write",
"params": {
"periphId": "servo1",
"value": "0"
}
}
]
}Card Swipe Display UID
{
"name": "Display Card Number",
"enabled": true,
"triggers": [
{
"type": "event",
"params": {
"periphId": "rfid1",
"eventCode": 120
}
}
],
"actions": [
{
"type": "display_write",
"params": {
"periphId": "oled1",
"template": "Card:\n{rfid1.uid}"
}
}
]
}Notes
- Firmware Version: Standard / Full firmware includes RFID driver; Lite does not support it by default
- Voltage Requirement: MFRC522 module must use 3.3V power supply; 5V will damage the module
- SPI Conflict: If using SD card or other SPI devices simultaneously, different CS pins must be used
- Read Distance: Typical read distance is 2-5cm, affected by card type and antenna quality
- Multi-Card Handling: Can only read one card at a time when multiple cards are present; operate one at a time
- UID Uniqueness: Some low-cost cards may have duplicate UIDs; verify sector data for security scenarios
