WOKWI board-mfrc522 RFID Reader
- MFRC522 Basic Reading - Basic RFID card detection with ESP32
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 5
#define RST_PIN 21
MFRC522 rfid(SS_PIN, RST_PIN);
void setup() {
Serial.begin(115200);
SPI.begin();
rfid.PCD_Init();
Serial.println("MFRC522 Ready");
}
void loop() {
delay(10);
if (!rfid.PICC_IsNewCardPresent()) {
return;
}
if (!rfid.PICC_ReadCardSerial()) {
return;
}
Serial.print("UID:");
for (byte i = 0; i < rfid.uid.size; i++) {
Serial.print(rfid.uid.uidByte[i] < 0x10 ? ":0" : ":");
Serial.print(rfid.uid.uidByte[i], HEX);
}
Serial.println();
rfid.PICC_HaltA();
delay(1000);
}
board-mfrc522 RFID Reader
MFRC522 RFID/NFC reader module with SPI interface for reading 13.56 MHz MIFARE cards and tags.
Pin names
| Name | Description |
|---|---|
| 3.3V | Voltage supply (3.3V) |
| RST | Reset (active low) |
| GND | Ground |
| IRQ | Interrupt request (active low) |
| MISO | SPI data out |
| MOSI | SPI data in |
| SCK | SPI clock |
| SDA | SPI chip select (active low) |
Attributes
| Name | Description | Default value |
|---|---|---|
| uid | Custom UID (for Blue Card only) | "" |
UID format
The UID can be specified in the following lengths:
- 4 bytes:
01:02:03:04(MIFARE Classic) - 7 bytes:
04:11:22:33:44:55:66(MIFARE Ultralight)
Each byte must be two hexadecimal characters (00-FF), separated by colons.
Card presets
The simulator provides built-in card presets for quick testing. Click on the MFRC522 to open the control panel where you can select a card:
| Index | Preset | Color | UID | Card Type |
|---|---|---|---|---|
| 0 | Blue Card | Blue | 01:02:03:04 | MIFARE Classic 1K |
| 1 | Green Card | Green | 11:22:33:44 | MIFARE Classic 1K |
| 2 | Yellow Card | Yellow | 55:66:77:88 | MIFARE Classic 1K |
| 3 | Red Card | Red | AA:BB:CC:DD | MIFARE Classic 1K |
| 4 | NFC Tag | Gray | 04:11:22:33:44:55:66 | MIFARE Ultralight |
| 5 | Key Fob | Orange | C0:FF:EE:99 | MIFARE Mini |
The uid attribute only affects the Blue Card (index 0). Other cards always use their preset UIDs. This lets you customize your main card while keeping the others for multi-user testing.


沒有留言:
張貼留言