How to get started with the Mifare MF522-AN and Arduino

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

2. Software

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!

14 thoughts on “How to get started with the Mifare MF522-AN and Arduino

  1. Hi Grant,

    I just received my RFID module and was able to test it using the sample code and it reading the card and sending its info through serial.

    However i would like to make a more complete code but i can not find information or code samples, do you have info or code samples that you can share with me?

    I will appreciate your help

    Regards

    Eduardo

    Like

  2. Hi Eduardo,

    The link posted by ‘mz’ above contains lots of examples. I haven’t done any more with RFID myself, so I can’t really help at the moment beyond pointing you to those examples.

    Hope that helps.
    Grant

    Like

  3. MZ – I haven’t tried writing to cards myself so I can’t really help. The B2CQ Shop example does include attempts to write data to the tag, so if that’s not working for you it’s possible that your tags are read-only. As I understand it, some cards don’t have storage so can’t be written to.

    Like

  4. Ive got the code running but can any one explain how the password code works .his comments say put your password in or something

    Like

  5. Hi. I’ve bought the same card and I’ve tried with the sample file, but, as you say it’s hard.

    I work in a school and I want to install a security open door system. The teachers and staff would have a tag and they could open main doors, but in case of fire the that system would be unlocked by the fire alarm.

    For that I’ve bought a RFID open system (keyboard with RFID reader + power supply + magnetic lock). The keyboard has a sample tag and a sample card.

    I wanted to know the way to read that sample tag/card and copy them to new tags with the arduino card and write/read module.

    I’ll follow this post. Thanks for your work.

    Like

  6. Hi, I’ve noticed a number of comments requesting help regarding getting started with MF522-AN. I purchased one of these reader/writer myself, and soon run into the same problem most of you on here seem to be facing, since then I’ve acquired alot of information and practical experience regarding the device. To anybody who wants to get into more than just using the device to open doors etc, I would suggest using this device:
    http://www.ebay.co.uk/itm/130649910994?ssPageName=STRK:MEWAX:IT&_trksid=p3984.m1438.l2649

    it’s the same as the MF522-AN, but it allows you to program it using the Arduino serial bus, rather then SPI. The device has much easier commands, making it much easier to program. At this present time, I am writing a Visual Basic interface:

    Sorry about the quality of the video, that will allow uses to fully program, and read their cards etc without writing a line of code. Hopefully, I’ll finish this project in a couple of weeks. I would just like to thank Grant once again for the help when I first started with these devices a month ago.

    Like

  7. Hi Luis, the read/writer you have bought is a 13.56mhz system, each card/tag has its own ID which is written to the card/tag at the factory during the time of manufacture, it is not possible to write this ID to other cards. It is however possible to achieve what your after using the 125khz system, I believe their IDs can be copied. Hope this was helpful to you!

    Like

  8. Hi,
    I want to use RFID-RC522 via uard, not spi.
    I don’t want anything complex ,
    I want just to detect if a card is near the detector.
    I don’t want to write data to card or know it’s id.
    I want just to know if a card is near the detector,
    maybe whith a signal from irq pin.
    I want also the simplest posible code,
    Or a sequence of bytes which if i send it
    to rc522 then rc522 will be properly set
    to act this way.
    Thangs you in advance.

    Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.