Advanced Arduino driver library for MFRC522 and other RFID RC522 based modules.
Read and write different types of Radio-Frequency IDentification (RFID) cards on your Arduino using a RC522 based reader connected via the Serial Peripheral Interface (SPI) or I2C interface.
Feature status: open; focus on rfid; no applications;
Code status: open; fixes/typos or documentation updates; no specific code for other boards; avoid examples;
Maintenance status: sporadically;
Please notice that there are many sellers (ebay, aliexpress, ...) who sell MFRC522 boards. The quality of these boards are extremely different. Some are soldered with wrong/low quality capacitors or fake/defect MFRC522.
Please consider buying several devices from different suppliers. So the chance of getting a working device is higher.
If you got a bad board and you can tell us how to detect those boards (silk, chip description, ...), please share your knowledge.
Works
Works partially
Doesn't work
Need more?
This library works with Arduino IDE 1.6, older versions are not supported and will cause compiler errors. The built-in library manager is supported.
If you use your own compiler, you have to enable c++11
-support.
This library is compatible with boards implementing the Arduino-API. You also have to change pins. See pin layout.
Some user made some patches/suggestions/ports for other boards:
First checkout what works and not and troubleshooting .
It seems to be a hardware issue or you need support to program your project? Please ask in the official Arduino forum, where you would get a much faster answer than on GitHub.
It seems to be a software issue? Open an issue on GitHub.
Please use fixed integers
, see stdint.h.
Why? This library is compatible with different boards which use different architectures (16bit and 32bit).
Unfixed int
variables have different sizes in different environments and may cause unpredictable behaviour.
The following tables show the typical pin layout used.
Notes:
RST
pin of the microcontroller-board is configurable, typically defined as RST_PIN
in sketch/program.SDA
pin of the microcontroller-board is configurable, typically defined as SS_PIN
in sketch/program.Signal | MFRC522 | Uno / 101 | Mega | Nano v3 | Leonardo / Micro | Pro Micro | Yun |
---|---|---|---|---|---|---|---|
RST/Reset | RST | 9 | 5 | D9 | RESET / ICSP-5 | RST | Pin9 |
SPI SS | SDA | 10 | 53 | D10 | 10 | 10 | Pin10 |
SPI MOSI | MOSI | 11 / ICSP-4 | 51 | D11 | ICSP-4 | 16 | ICSP4 |
SPI MISO | MISO | 12 / ICSP-1 | 50 | D12 | ICSP-1 | 14 | ICSP1 |
SPI SCK | SCK | 13 / ICSP-3 | 52 | D13 | ICSP-3 | 15 | ICSP3 |
Signal | MFRC522 | Wemos D1 mini |
---|---|---|
RST/Reset | RST | D3 |
SPI SS | SDA | D8 |
SPI MOSI | MOSI | D7 |
SPI MISO | MISO | D6 |
SPI SCK | SCK | D5 |
Signal | MFRC522 | WROOM-32 |
---|---|---|
RST/Reset | RST | 21 |
SPI SS | SDA | 5 |
SPI MOSI | MOSI | 23 |
SPI MISO | MISO | 19 |
SPI SCK | SCK | 18 |
Signal | MFRC522 | 2.0 | ++2.0 | 3.1 |
---|---|---|---|---|
RST/Reset | RST | 7 | 4 | 9 |
SPI SS | SDA | 0 | 20 | 10 |
SPI MOSI | MOSI | 2 | 22 | 11 |
SPI MISO | MISO | 3 | 23 | 12 |
SPI SCK | SCK | 1 | 21 | 13 |
There are three hardware components involved:
Microcontroller
Proximity Coupling Device (PCD)
Proximity Integrated Circuit Card (PICC)
The microcontroller and the reader use SPI for communication.
The reader and the tags communicate using a 13.56 MHz electromagnetic field.
The UID of a card can not be used as a unique identification for security related projects. Some Chinese cards allow to change the UID which means you can easily clone a card. For projects like access control, door opener or payment systems you must implement an additional security mechanism like a password or normal key.
This library only supports crypto1
-encrypted communication. Crypto1
has been known as broken for a few years, so it does NOT offer ANY security, it is virtually unencrypted communication.
Do not use it for any security related applications!
This library does not offer 3DES or AES authentication used by cards like the Mifare DESFire, it may be possible to be implemented because the datasheet says there is support. We hope for pull requests :).
I don't get input from reader or WARNING: Communication failure, is the MFRC522 properly connected?
Firmware Version: 0x12 = (unknown) or other random values.
PCD_Init()
to be ready. As workaround add a delay(4)
directly after PCD_Init()
to give the PCD more time.Sometimes I get timeouts or sometimes tag/card does not work.
MFRC522.PCD_SetAntennaGain(MFRC522.RxGain_max);
.My tag/card doesn't work.
My mobile phone doesn't recognize the MFRC522 or my MFRC522 can't read data from other MFRC522.
I can only read the card UID.
AccessBits
have been accidentally set and now an unknown password is set. This can not be reverted.I need more features.
PN532
(supports NFC and many more, but costs about $15).GNU LESSER GENERAL PUBLIC LICENSE, Version 2.1.
It is not allowed to change the license.
Arduino.h
SPI.h
stdint.h
The MFRC522 library was first created in Jan 2012 by Miguel Balboa (from http://circuitito.com) based on code by Dr. Leong (from http://B2CQSHOP.com) for "Arduino RFID module Kit 13.56 Mhz with Tags SPI W and R By COOQRobot".
It was translated into English and rewritten/refactored in the fall of 2013 by Søren Thing Andersen (from http://access.thing.dk).
It has been extended with functionality to alter sector 0 on Chinese UID changeable MIFARE card in Oct 2014 by Tom Clement (from http://tomclement.nl).
Maintained by miguelbalboa until 2016. Maintained by Rotzbua from 2016 until 2022.