Wiring guide

How to wire an RC522 RFID reader to an ESP32

To wire an RC522 RFID reader to an ESP32, connect 3.3V to 3V3, GND to GND, SDA to GPIO 5 (D5), SCK to GPIO 18 (D18), MOSI to GPIO 23 (D23), MISO to GPIO 19 (D19) and RST to GPIO 4 (D4). The ESP32 and the MFRC522 are both 3.3 V, so the SPI lines connect directly. The sketch below uses the MFRC522 (MFRC522.h) library. It reads the card that is held to the reader and prints its UID.

  • 3.3 V logic
  • Library: MFRC522.h
  • 7 wires
ESP32 · RC522 RFID readerlive0.000 s 0.00x
Click to open it in the editor
The circuit itself, running on the simulator with the sketch below. Press what can be pressed; click anything else to open it in the editor.
Pin to pin

RC522 RFID reader to ESP32 wiring table

Every wire in the circuit above, with the part’s pin names and the board’s own labels. The wire colors are the ones the circuit uses; on a real bench any colors work.

RC522 RFID reader pinESP32 pinWire colorWhy
3.3V3V3redThe MFRC522 is a 3.3 V chip. Never 5 V on this pin.
GNDGNDblueCommon ground.
SDA (SS)GPIO 5 (D5)amberChip select. Labeled SDA on the module, but this is SPI, not I2C.
SCKGPIO 18 (D18)cyanESP32’s SPI clock.
MOSIGPIO 23 (D23)violetData from the board to the reader.
MISOGPIO 19 (D19)greenData from the reader to the board.
RSTGPIO 4 (D4)grayReset, held high while the reader runs.
IRQnot connectedn/aThe library polls instead.
Voltage

Power and logic levels for RC522 RFID reader and ESP32

Logic level

The ESP32’s GPIO pins are 3.3 V logic and are not 5 V tolerant. Nothing wired to a pin may go above 3.3 V.

Supply

The RC522 RFID reader takes 3.3 V from 3V3. That pin is the ESP32’s own regulated 3.3 V output.

This pair

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

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.

The sketch

The working code for the ESP32

Library: MFRC522 (MFRC522.h). This is the sketch the circuit above runs.

RC522 RFID on ESP32
#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
}
Output

What you should see

Open the serial monitor at 115200 baud. The sketch prints Hold a card to the reader and, when you present the card in the circuit, a Card UID line with its four bytes in hexadecimal.

The pin labeled SDA on the module is the SPI chip select, not an I2C line. IRQ is left unconnected because the library polls.

The serial monitor prints this, recorded from the circuit above with a card presented after 400 ms:

Hold a card to the reader
Card UID: C3 5A 1E 94
Pitfalls

Common mistakes wiring an RC522 RFID reader to an 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.

Build your own RC522 RFID reader project

Open this circuit in the editor, change the wiring or the code, and keep your version in a free account.