RC522 RFID with Arduino Mega 2560 R3

Wiring for the RC522 RFID reader (13.56 MHz) on the Arduino Mega 2560 R3 (ATmega2560, 5 V logic), chosen with the same pin rules BoardPilot uses: default buses first, and no pins that are used for flash, USB, the debugger or booting.

Wiring

RC522 RFID pinRoleArduino Mega 2560 R3 pinNotes
SDASPI chip select53 (PB0)This is the SPI chip select (CS), despite the SDA label
SCKSPI clock52 (PB1)
MOSISPI MOSI51 (PB2)
MISOSPI MISO50 (PB3)
IRQInterrupt~2 (PE4)Interrupt, optional. Leave unconnected
GNDGroundGND
RSTInput to the part22 (PA0)Reset, active LOW
3.3VPower3.3V3.3 V only. Never 5 V

Check before you power it on

Test code (Arduino)

// Library: MFRC522 (miguelbalboa)
#include <SPI.h>
#include <MFRC522.h>

MFRC522 rfid(53, 22);  // SDA is the SPI chip select

void setup() {
  Serial.begin(115200);
  SPI.begin();
  rfid.PCD_Init();
  rfid.PCD_DumpVersionToSerial();  // 0x91 or 0x92 means the reader answers
}

void loop() {
  if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) return;
  for (byte i = 0; i < rfid.uid.size; i++) Serial.print(rfid.uid.uidByte[i], HEX);
  Serial.println();
  rfid.PICC_HaltA();
}

Arduino board: arduino:avr:mega.

Questions

Which Arduino Mega 2560 R3 pins do I use for the RC522 RFID?

SDA → 53 (PB0), SCK → 52 (PB1), MOSI → 51 (PB2), MISO → 50 (PB3), IRQ → ~2 (PE4), GND → GND, RST → 22 (PA0), 3.3V → 3.3V.

Does the RC522 RFID work with the Arduino Mega 2560 R3 at 5 V?

The RC522 RFID is a 3.3 V part and the Arduino Mega 2560 R3 uses 5 V signals. Power it from 3.3 V and put a level shifter on the signal wires, or buy a 5 V version of the module.

BoardPilot checks this wiring in 3D as you build it, and finds crossed or missing wires on the real board.

Download BoardPilot

Full Arduino Mega 2560 R3 pinout · RC522 RFID reader (13.56 MHz): all pins and data

The RC522 RFID on other boards

Other parts on the Arduino Mega 2560 R3