Within an hour of my video upload last night I already had someone asking how to do it. It’s a good question – despite the popularity of the Philips/NXP MFRC522 RFID chip and the MF522-AN board based on it, there’s actually very little online in the way of tutorials or source code to get started.
Here’s how I got up and running and to my first ‘hello world’ test…
1. Hardware setup
This is the RFID reader I bought off eBay – RFID module Kit 13.56 Mhz with Tags SPI
Although the board has header pins they don’t line up with Arduino (as they would on a regular shield) so a breadboard is the easiest way to match the pins to the relevant in/outs on the Arduino.
If you’re using an Arduino Uno the pins map as follows:
- Reset > Pin 5
- SS > Pin 10
- MOSI > Pin 11
- MISO > Pin 12
- SCK > Pin 13
- Ground > Ground
- 3.3v > 3.3v
Example sketches for this board are really hard to come by. I eventually found an example written by the guys at B2CQ Shop which covers pretty much everything you’d want to do – identifying cards, reading their data and, if the card supports it, writing data back.
Since I found the sketch so hard to come by (and I can’t actually find the source again now!) I’ve shared my modified version below. This version is just tweaked slightly to respond to a couple of specific cards. However all of the original code and comments are still in there, so it shouldn’t take long to work out what you need to uncomment in order to restore/tweak functionality.
Code is here: ggrfid.ino
A reader by the name of Robson used Google Translate to translate the Chinese comments into English, which actually makes the sample code much easier to follow. Here’s the version he provided: gggrfid_en_ino.txt
I hope this helps someone. If anyone has any questions please feel free to get in touch. And if you make something cool with it please share your examples. Thanks!