Raspberry Pi Pico · RC522 RFID

Raspberry Pi Pico RC522 RFID Simulator: Wiring, Code and a Live Circuit

This is an RC522 (MFRC522) RFID reader wired to a Raspberry Pi Pico 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 Raspberry Pi Pico’s SPI pins, and RST to GP20 (physical pin 26).

  • 3.3 V logic
  • Library: MFRC522.h
  • SS on GP17 (physical pin 22)
  • 3.3 V module
Raspberry Pi Pico · RC522 RFIDlive0.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.

Wiring the RC522 RFID to the Raspberry Pi Pico

Every connection in the circuit above, with the board’s own pin names.

RC522 RFID pinRaspberry Pi Pico pinWhy
3.3V3V3(OUT)The MFRC522 is a 3.3 V chip. Never 5 V on this pin.
GNDGNDCommon ground.
SDA (SS)GP17 (physical pin 22)Chip select. Labeled SDA on the module, but this is SPI, not I2C.
SCKGP18 (physical pin 24)Raspberry Pi Pico’s SPI clock.
MOSIGP19 (physical pin 25)Data from the board to the reader.
MISOGP16 (physical pin 21)Data from the reader to the board.
RSTGP20 (physical pin 26)Reset, held high while the reader runs.
IRQnot connectedThe library polls instead.

The Raspberry Pi Pico 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 Raspberry Pi Pico

The numbers in the code are GP numbers, not the physical pin numbers printed beside the header: GP15 is pin 20. GP23 to GP25 are used on the board itself, and GP25 is the LED.

On a real bench

Solder headers on the Pico and press it into the breadboard across the center channel; the RC522 RFID goes in beside it. GND pins sit every fifth pin down both sides (pins 3, 8, 13, 18 and so on), so there is always one close. The first upload needs BOOTSEL held while plugging in.

The code

The sketch the circuit above runs. Open it in the editor, change a line and press Run: it compiles in your browser.

RC522 RFID on Raspberry Pi Pico
#include <SPI.h>
#include <MFRC522.h>

const int SS_PIN = 17;    // SDA on the module, GP17 (physical pin 22)
const int RST_PIN = 20;   // GP20 (physical pin 26)

MFRC522 rfid(SS_PIN, RST_PIN);

void setup() {
  Serial.begin(115200);
  SPI.begin();          // SCK 18, MISO 16, MOSI 19
  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 Raspberry Pi Pico’s SPI bus on its own pins (SCK 18, MISO 16, MOSI 19), 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 the USB port at 115200 baud in this sketch; on a real Pico it appears once the board has enumerated.

Common mistakes with the RC522 RFID on the Raspberry Pi Pico

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.

Mixing up SPI0 and SPI1

SPI.begin() uses SPI0 on GP16 to GP19. Pico tutorials sometimes put the reader on SPI1 (GP10 to GP13), which needs SPI1.begin() and a different object.

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 a Raspberry Pi Pico?

Yes. The circuit at the top of this page is a Raspberry Pi Pico with a RC522 RFID reader, running in your browser on a simulated RP2040. 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 Raspberry Pi Pico?

SPI: SCK on GP18 (physical pin 24), MISO on GP16 (physical pin 21), MOSI on GP19 (physical pin 25). SS and RST can be any digital pins; this page uses GP17 (physical pin 22) and GP20 (physical pin 26).

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.