Learn
Reading RFID Tags with an RC522 on a Raspberry Pi 4B
Wire an RC522 RFID reader to the Raspberry Pi's SPI pins and read a tag's real UID bytes with the standard mfrc522 Python library — then tap a virtual RFID tag on the canvas to see it work.
Note: the RC522 RFID Reader is a VIP-tier component in the simulator — you’ll need a VIP plan to use it there.
Try this directly in the free Raspberry Pi 4B simulator — no hardware or signup required. New to the GPIO header? Start with the interactive pinout guide.
What you’ll need
- Raspberry Pi 4B
- RC522 RFID Reader
- RFID Tag / Card
Step by step
- Drag Raspberry Pi 4B onto the Canvas.
- Drag an RC522 RFID Reader onto the Canvas. Hover over its 8 pins to see the labels: SDA (SS), SCK, MOSI, MISO, IRQ, GND, RST and 3.3V.
- Drag an RFID Tag / Card onto the Canvas. It has no pins — it's wireless. Click it and set its UID in the settings panel (for example DE:AD:BE:EF).
- Wire the reader to the Pi's SPI pins and power:
| RC522 pin | Wire to |
|---|---|
| SDA (SS) | Pi pin 24 (GPIO8, SPI CE0) |
| SCK | Pi pin 23 (GPIO11, SPI clock) |
| MOSI | Pi pin 19 (GPIO10) |
| MISO | Pi pin 21 (GPIO9) |
| RST | Pi pin 22 (GPIO25) |
| GND | a Pi GND pin |
| 3.3V | Pi pin 1 (3.3V) — never a 5V pin |
| IRQ | leave unconnected |
The RC522 is a 3.3V-only part. The Pi's GPIO pins are also 3.3V, so no level shifter is needed for the signal lines. Only the power pin matters: wiring 3.3V to a 5V pin makes the Console print a warning, just as it would flag a real risk of damage.
- Go to the Code tab and write a script that reads the tag's UID:
import asynciofrom mfrc522 import MFRC522 reader = MFRC522() while not should_stop(): (status, tag_type) = reader.MFRC522_Request(reader.PICC_REQIDL) if status == reader.MI_OK: (status, uid) = reader.MFRC522_Anticoll() if status == reader.MI_OK: print("Card UID:", [hex(b) for b in uid[:4]]) await asyncio.sleep(0.3)The first run downloads the mfrc522 library, so Start can take a few seconds. The library talks to the reader over real SPI transfers; the simulator answers them like the RC522 chip does.
- Click Start.
- Click the circle in the middle of the RFID tag. It stays "tapped" for about 1.5 seconds, as if held against the reader.
The Console prints the tag's UID bytes, for example Card UID: ['0xde', '0xad', '0xbe', '0xef']. The fifth byte the library reads is a check byte (BCC), which is why only the first four are printed.
What “working correctly” looks like
- Nothing prints while no tag is tapped — the reader just keeps polling.
- While the tag is tapped, the Console prints the exact UID you set on the tag, roughly every 0.3 seconds.
- Change the tag's UID in its settings (stop the simulation first) and the printed bytes change to match.
If something’s wrong
- Nothing ever prints → confirm 3.3V and GND are wired to real Pi pins, SDA is on pin 24, and you clicked the tag while the simulation was running.
- The library fails to import → wait for the first-run download to finish, and make sure the script contains the word mfrc522 in its import.
- A warning about 5V on the RC522 → move the 3.3V wire from a 5V pin to pin 1.
- Readings take a moment to appear → each SPI transfer waits for the next screen frame, so a full read takes about half a second.
- SimpleMFRC522's read() and write() (tag data blocks) are not supported — only reading the UID is.