.. image:: https://img.shields.io/maintenance/no/2019.svg
:target: development
.. image:: https://github.com/miguelbalboa/rfid/workflows/PlatformIO%20CI/badge.svg
:target: https://github.com/miguelbalboa/rfid/actions
:alt: GitHub Actions
.. image:: https://img.shields.io/badge/C%2B%2B-11-brightgreen.svg
:target: compatible ide
.. image:: https://img.shields.io/github/release/miguelbalboa/rfid.svg?colorB=green
:target: https://github.com/miguelbalboa/rfid/releases
:alt: Releases
.. image:: https://img.shields.io/badge/ArduinoIDE-%3E%3D1.6.10-lightgrey.svg
:target: compatible ide
_
Arduino 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) interface.
For advanced and further development please use library RFID_MFRC522v2 <https://github.com/OSSLibraries/Arduino_MFRC522v2>
_.
The development by owner miguelbalboa has ended.
Feature status: complete freeze; no function or API change.
Code status: partial freeze; just fixes/typos or documentation updates; no extensions for other boards; no new examples.
Maintenance status: sporadically.
Why no further development? This library has a long history and is used in many projects. These projects often do not document what version they use. Committing changes might break those old projects and lead to bad experiences (for beginners) and support requests. For these reasons the library is in freeze mode. You can still commit typo, documentation or bug fixes.
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
#191 <https://github.com/miguelbalboa/rfid/issues/191#issuecomment-242631153>
_.Doesn't work
supported by hardware
_.supported by hardware
_.supported by hardware
_.#310 <https://github.com/miguelbalboa/rfid/issues/310>
__, not supported by software.#269 <https://github.com/miguelbalboa/rfid/issues/269>
_, not supported by software.#240 <https://github.com/miguelbalboa/rfid/issues/240>
_, not supported by software.#281 <https://github.com/miguelbalboa/rfid/issues/281>
_, not supported by software.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.
!!!Only for advanced users!!!
This library is compatible with the Teensy and ESP8266 if you use the board plugin of the Arduino IDE. Not all examples are available for every board. You also have to change pins. See pin layout
_.
Some user made some patches/suggestions/ports for other boards:
Note that the main target/support of library is still Arduino.
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 table shows the typical pin layout used:
+-----------+----------+-----------------------------------------------------------------------------------+ | | PCD | Arduino | | +----------+-------------+---------+---------+-----------------+-----------+---------+---------+ | | MFRC522 | Uno / 101 | Mega | Nano v3 |Leonardo / Micro | Pro Micro | Yun [4]| Due | +-----------+----------+-------------+---------+---------+-----------------+-----------+---------+---------+ | Signal | Pin | Pin | Pin | Pin | Pin | Pin | Pin | Pin | +===========+==========+=============+=========+=========+=================+===========+=========+=========+ | RST/Reset | RST | 9 [1] | 5 [1] | D9 | RESET / ICSP-5 | RST | Pin9 | 22 [1] | +-----------+----------+-------------+---------+---------+-----------------+-----------+---------+---------+ | SPI SS | SDA [3] | 10 [2] | 53 [2] | D10 | 10 | 10 | Pin10 | 23 [2] | +-----------+----------+-------------+---------+---------+-----------------+-----------+---------+---------+ | SPI MOSI | MOSI | 11 / ICSP-4 | 51 | D11 | ICSP-4 | 16 | ICSP4 | SPI-4 | +-----------+----------+-------------+---------+---------+-----------------+-----------+---------+---------+ | SPI MISO | MISO | 12 / ICSP-1 | 50 | D12 | ICSP-1 | 14 | ICSP1 | SPI-1 | +-----------+----------+-------------+---------+---------+-----------------+-----------+---------+---------+ | SPI SCK | SCK | 13 / ICSP-3 | 52 | D13 | ICSP-3 | 15 | ICSP3 | SPI-3 | +-----------+----------+-------------+---------+---------+-----------------+-----------+---------+---------+
+-----------+---------------+--------------------------+-------------+ | | ESP8266 | Teensy | 8F328P-U | | +---------------+--------+--------+--------+-------------+ | | Wemos D1 mini | 2.0 | ++ 2.0 | 3.1 | ALPHA | +-----------+---------------+--------+--------+--------+-------------+ | Signal | Pin | Pin | Pin | Pin | Pin [5] | +===========+===============+========+========+========+=============+ | RST/Reset | D3 | 7 | 4 | 9 | D9# [1] | +-----------+---------------+--------+--------+--------+-------------+ | SPI SS | D8 | 0 | 20 | 10 | D10# [2]_ | +-----------+---------------+--------+--------+--------+-------------+ | SPI MOSI | D7 | 2 | 22 | 11 | MOSI / D11# | +-----------+---------------+--------+--------+--------+-------------+ | SPI MISO | D6 | 3 | 23 | 12 | MISO / D12# | +-----------+---------------+--------+--------+--------+-------------+ | SPI SCK | D5 | 1 | 21 | 13 | SCK | +-----------+---------------+--------+--------+--------+-------------+
.. [1] Configurable, typically defined as RST_PIN in sketch/program.
.. [2] Configurable, typically defined as SSPIN in sketch/program.
.. [3] The SDA pin might be labeled SS on some/older MFRC522 boards.
.. [4] Source: #111 <https://github.com/miguelbalboa/rfid/issues/111#issuecomment-420433658>
.
.. [5] Pin names from the back (empty) side of the board were used as more definitive.
Important: If your micro controller supports multiple SPI interfaces, the library only uses the default (first) SPI of the Arduino framework.
There are three hardware components involved:
An Arduino
_ or compatible executing the Sketch using this library.
Prices vary from USD 7 for clones, to USD 75 for "starter kits" (which might be a good choice if this is your first exposure to Arduino; check if such kit already includes the Arduino, Reader, and some Tags).
The PCD is the actual RFID Reader based on the NXP MFRC522
_ Contactless
Reader Integrated Circuit.
Readers can be found on eBay
_ for around USD 5: search for "rc522".
You can also find them on several web stores. They are often included in "starter kits", so check your favourite electronics provider as well.
The PICC is the RFID Card or Tag using the ISO/IEC 14443A
_
interface, for example Mifare or NTAG203.
One or two might be included with the Reader or "starter kit" already.
The protocol is described in the NXP MFRC522
_ datasheet.
See the Pin Layout
_ section for details on connecting the pins.
The protocol is defined in ISO/IEC 14443-3:2011 Part 3 Type A.
Details are found in chapter 6 "Type A – Initialization and anticollision".
See http://wg8.de/wg8n1496_17n3613_Ballot_FCD14443-3.pdf for a free version of the final draft (which might be outdated in some areas).
The reader does not support ISO/IEC 14443-3 Type B.
The UID of a card can not be used as an 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?
Pin Layout
_ .Pin Layout
_ .PCD_Init()
can help.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.
security
or different protocol
.Mikro Elektronika
_)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.Where do I get more information?
Arduino Forum <https://forum.arduino.cc/>
or StackOverflow <https://stackoverflow.com/questions/tagged/mifare>
.community mfrc522 wiki <https://github.com/miguelbalboa/rfid/wiki>
_ .I need more features.
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.
In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to https://unlicense.org/
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.
.. _arduino: https://arduino.cc/ .. _ebay: https://www.ebay.com/ .. _iso/iec 14443a: https://en.wikipedia.org/wiki/ISO/IEC_14443 .. _iso/iec 14443-3\:2011 part 3: .. _nxp mfrc522: https://www.nxp.com/docs/en/data-sheet/MFRC522.pdf .. _broken: https://eprint.iacr.org/2008/166 .. _supported by hardware: https://web.archive.org/web/20151210045625/http://www.nxp.com/documents/leaflet/939775017564.pdf .. _Arduino forum: https://forum.arduino.cc .. _stdint.h: https://en.wikibooks.org/wiki/C_Programming/C_Reference/stdint.h .. _Mikro Elektronika: https://forum.mikroe.com/viewtopic.php?f=147&t=64203