Skip to content

Example 43: RFID Card (MFRC522) ​

Experiment Overview ​

MFRC522 is a 13.56MHz SPI RFID reader for MIFARE cards. FastBee includes the driver in the release baseline.

Note: This feature requires FASTBEE_ENABLE_RFID=1 and active rfid.

Hardware Wiring ​

Board LabelGPIO PinConnected Device
SDA(SS)GPIO5MFRC522 SDA (Chip Select)
SCKGPIO18MFRC522 SCK
MOSIGPIO23MFRC522 MOSI
MISOGPIO19MFRC522 MISO
RSTGPIO27MFRC522 RST (Reset)

MFRC522 requires 3.3V power supply; do NOT connect to 5V!

JSON Configuration Example ​

json
{
  "peripherals": [
    {
      "id": "rfid_01",
      "name": "RFID Reader",
      "type": 38,
      "enabled": false,
      "pins": [5, 18, 23, 19, 27],
      "params": {
        "category": "rfid"
      }
    }
  ]
}

Peripheral Execution Linkage ​

Scenario 1: Card Swipe Unlock (Event Trigger) ​

Feature: When RFID card is detected, open relay for 3 seconds then close

Web UI Configuration Steps ​

Step 1: Ensure Relay Peripheral is Configured

  • Peripheral ID: relay_01
  • Type: GPIO Output

Step 2: Create Rule

  1. Click Peripheral Execution in the left menu
  2. Click New Rule button
  3. Fill in basic configuration:
    • Rule Name: RFID Unlock
    • Report Data: ✅ Enabled
    • Enable: ✅ Enabled

Step 3: Configure Trigger (Event Trigger)

  1. Click Add Trigger button

  2. Fill in trigger configuration:

    FieldValueDescription
    Trigger TypeSelect Event TriggerRFID card swipe event
    Event Type120RFID card detected
    Event SourceSelect rfid_01RFID reader

Step 4: Configure Actions (3 actions required)

Action 1: Open Relay

  1. Click Add Action button
  2. Fill in:
    • Action Type: Select HIGH
    • Target Peripheral: Select relay_01

Action 2: Delay 3 Seconds

  1. Click Add Action button again
  2. Fill in:
    • Action Type: Select Delay
    • Delay Time: 3000 (3000ms = 3 seconds)

Action 3: Close Relay

  1. Click Add Action button a third time

  2. Fill in:

    • Action Type: Select LOW
    • Target Peripheral: Select relay_01
  3. Click Save button


Scenario 2: Card Removal Event (Event Trigger) ​

Feature: Turn off LED when RFID card is removed

Configuration Steps:

  1. Create rule, name: RFID Card Removed
  2. Trigger configuration:
    • Trigger Type: Select Event Trigger
    • Event Type: 121 (RFID card removed)
    • Event Source: Select rfid_01
  3. Action configuration:
    • Action Type: Select HIGH (LED off)
    • Target Peripheral: Select led_d1
  4. Click Save

RFID Specifications ​

FeatureDescription
Operating Frequency13.56MHz
Supported CardsMifare series IC cards
Read Distance3-5cm
UID Format4-byte hexadecimal (e.g., A1B2C3D4)
Polling RateInternal 200ms polling

Notes ​

  1. Firmware State: Confirm rfid is compiled and active
  2. Power Supply: MFRC522 must use 3.3V; 5V will damage the chip
  3. Read Distance: Typical card reading distance is 3-5cm
  4. UID Format: Card UID is 4-byte hexadecimal, e.g., A1B2C3D4
  5. SPI Pins: Pin order is SS, SCK, MOSI, MISO, RST
  6. Polling Rate: Driver internally polls for cards every 200ms

FastBee | fastbee.cn