ESP32 RC522 RFID Simulator: Wiring, Code and a Live Circuit
This is an RC522 (MFRC522) RFID reader wired to an ESP32 DevKit over SPI, running live with the MFRC522 library: open it in the editor, lay a card on the reader, and the serial monitor prints its UID.
Seven wires: 3.3 V, GND, the four SPI lines to the ESP32’s SPI pins, and RST to GPIO 4 (D4).
- 3.3 V logic
- Library: MFRC522.h
- SS on GPIO 5 (D5)
- 3.3 V module
Wiring the RC522 RFID to the ESP32
Every connection in the circuit above, with the board’s own pin names.
| RC522 RFID pin | ESP32 pin | Why |
|---|---|---|
| 3.3V | 3V3 | The MFRC522 is a 3.3 V chip. Never 5 V on this pin. |
| GND | GND | Common ground. |
| SDA (SS) | GPIO 5 (D5) | Chip select. Labeled SDA on the module, but this is SPI, not I2C. |
| SCK | GPIO 18 (D18) | ESP32’s SPI clock. |
| MOSI | GPIO 23 (D23) | Data from the board to the reader. |
| MISO | GPIO 19 (D19) | Data from the reader to the board. |
| RST | GPIO 4 (D4) | Reset, held high while the reader runs. |
| IRQ | not connected | The library polls instead. |
The ESP32 and the MFRC522 are both 3.3 V, so the SPI lines connect directly: the cleanest RC522 wiring there is.
Pins to leave alone on the ESP32
GPIO 34, 35, 36 (VP) and 39 (VN) are input only: they cannot drive a pin or take an internal pull-up. GPIO 0, 2, 5, 12 and 15 are strapping pins, read at power-on, and GPIO 6 to 11 are the flash chip.
On a real bench
The thirty-pin DevKit straddles a breadboard with one row of holes free on each side, which is where the RC522 RFID’s jumpers go. Many ESP32 boards are wider and cover both rows; then use two breadboards side by side. Hold BOOT while uploading if the IDE cannot connect.
The code
The sketch the circuit above runs. Open it in the editor, change a line and press Run: it compiles in your browser.
#include <SPI.h>
#include <MFRC522.h>
const int SS_PIN = 5; // SDA on the module, GPIO 5 (D5)
const int RST_PIN = 4; // GPIO 4 (D4)
MFRC522 rfid(SS_PIN, RST_PIN);
void setup() {
Serial.begin(115200);
SPI.begin(); // SCK 18, MISO 19, MOSI 23
rfid.PCD_Init();
Serial.println("Hold a card to the reader");
}
void loop() {
if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) {
delay(50);
return;
}
Serial.print("Card 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(); // done with this card until it is lifted
}
SPI.begin() starts the ESP32’s SPI bus on its own pins (SCK 18, MISO 19, MOSI 23), and MFRC522 rfid(SS_PIN, RST_PIN) adds the chip select and reset. PCD_Init() resets the reader and turns its antenna on.
PICC_IsNewCardPresent() asks whether a card has entered the field and PICC_ReadCardSerial() reads its UID, four or seven bytes. The sketch prints them in hex with a leading zero where needed, then PICC_HaltA() puts the card to sleep so it is reported once.
Serial.begin(115200) opens the serial monitor. Serial is UART0 on the USB bridge. ESP32 sketches usually run it at 115200 baud, which this one does.
Common mistakes with the RC522 RFID on the ESP32
Powering it from 5V
The 3.3V pin means it: 5 V there damages the MFRC522. If the module gets warm or reports a version of 0x00 or 0xFF, check this first.
Treating SDA as I2C
The pin marked SDA is the SPI chip select. Wired to the ESP32’s I2C data pin, the reader is never selected. It goes to SS_PIN, GPIO 5 (D5) here.
Expecting to read bank cards
The RC522 reads 13.56 MHz MIFARE tags and cards. Contactless bank cards answer, but only with a random ID each time, and 125 kHz key fobs not at all.
Questions and answers
Can I simulate an RC522 RFID reader with an ESP32 DevKit?
Yes. The circuit at the top of this page is an ESP32 DevKit with a RC522 RFID reader, running in your browser on a simulated ESP32 (Xtensa LX6). The simulated reader has four cards with fixed UIDs; click to lay one on the antenna. Press Run it in the editor to change the wiring or the code; it is free and needs no account.
Which pins does the RC522 use on the ESP32?
SPI: SCK on GPIO 18 (D18), MISO on GPIO 19 (D19), MOSI on GPIO 23 (D23). SS and RST can be any digital pins; this page uses GPIO 5 (D5) and GPIO 4 (D4).
How do I make an access control lock?
Compare the UID bytes with a list of allowed cards, and drive a relay or a servo when one matches. Keep in mind that a UID alone is easy to copy, so it is a learning project, not a security one.
Can I write to the card?
The library has MIFARE_Write() for MIFARE Classic blocks after authentication. This simulated reader models reading UIDs only.
Build your own RC522 RFID project
Open this circuit in the editor, change the wiring or the code, and keep your version in a free account.