Acoptex.Com

Learn ESP32, ESP8266, Arduino, and Raspberry Pi

Security Access using MFRC522 RFID Reader with Arduino

We are going to learn about the RFID RC522 module and how to use it with Arduino board.

Tag: Project 008 RFID RC522 module with LED

Dear visitors. You can support our project buy clicking on the links of parts and buying them or donate us to keep this website alive. Thank you. Acoptex.com

Project resources

Datasheet for the chip that used in modules can be found here.

Parts required

  1. Aruduino Uno R3 (you can also use the other version of Arduino)
Arduino Uno Rev 3

2.MFRC522 13.56Mhz IC or RFID RC522 module

MFRC522 13.56Mhz IC or RFID RC522 module

3.Arduino IDE ( you can download it from here  )

4.Jumper cables M-M, F-M

jumper cables

5. LED (can be red or green) 1 pc

LED

6. Resistor 1 pc (220 Ohm)

Resistor 220 Ohm

7. Breadboard 1 pc

Breadboard

Understanding the RFID

RFID, or Radio Frequency Identification, is a system for transferring data over short distances (typically less than 6 inches). Often only one of the two devices needs to be powered, while the other is a passive device. This allows for easy use in such things as credit cards, key fobs, and pet collars as there is no need to worry about battery life. The downside is that the reader and the information holder (i.e. credit card) must be very close, and can only hold small amounts of data. The microcontroller and card reader uses SPI for communication (chip supports I2C and UART protocols). The card reader and the tags communicate using a 13.56 MHz electromagnetic field. (ISO 14443A standart tags). You can use an RFID system to open a door. For example, only the person with the right information on his card can enter.

RFID system consists of two main components:
• a transponder/tag attached to an object to be identified, in this example we have a keychain and an electromagnetic card. Each tag has his own unique identification (UID).

RFID TAGS
  • two-way radio transmitter-receiver, a transceiver also known as interrogator/reader.
RFID

A reader consists of a Radio Frequency module and an antenna which generates high frequency electromagnetic field. On the other hand, the tag is usually a passive device, meaning it doesn’t contain a battery. Instead it contains a microchip that stores and processes information, and an antenna to receive and transmit a signal. To read the information encoded on a tag, it is placed in close proximity to the Reader (does not need to be within direct line-of-sight of the reader). A Reader generates an electromagnetic field which causes electrons to move through the tag’s antenna and subsequently power the chip. The powered chip inside the tag then responds by sending its stored information back to the reader in the form of another radio signal. This is called backscatter. The backscatter, or change in the electromagnetic/RF wave, is detected and interpreted by the reader which then sends the data out to a computer or microcontroller.

For most of the RFID based Arduino projects, RC522 RFID module is a great choice. It is low power, low cost, pretty rugged, easy to interface with and insanely popular among hobbyists.

The RC522 RFID module based on MFRC522 IC from NXP is one of the most inexpensive RFID options that you can get online for less than four dollars. It usually comes with a RFID card tag and key fob tag with 1KB memory. And best of all, it can write a tag, so you can store your some sort of secret message in it.

MFRC522 RFID Reader with Arduino Tutorial | Acoptex.com

The RC522 RFID Reader module is designed to create a 13.56MHz electromagnetic field that it uses to communicate with the RFID tags (ISO 14443A standard tags). The reader can communicate with a microcontroller over a 4-pin Serial Peripheral Interface (SPI) with a maximum data rate of 10Mbps. It also supports communication over I2C and UART protocols.

The module comes with an interrupt pin. It is handy as the module will alert us when a tag comes into its vicinity.

The operating voltage of the module is from 2.5 to 3.3V, but the good news is that the logic pins are 5-volt tolerant, so we can easily connect it to an Arduino or any 5V logic microcontroller without using any logic level converter.

Specifications:

Frequency Range: 13.56 MHz ISM Band
Host Interface: SPI / I2C / UART
Operating Supply Voltage: 2.5 V to 3.3 V
Max. Operating Current: 13-26mA
Min. Current(Power down): 10µA
Logic Inputs: 5V Tolerant
Read Range: 5 cm

Signals and connections of RFID RC522

The RC522 module has total 8 pins. The connections are as follows:

RFID RC522 module pinout
VCCsupplies power for the module from 2.5V to 3.3V. You can connect it to 3V3 pin of your Arduino board.
GNDground pin. Connect it to GND pin on the Arduino.
RST an input for Reset and power-down. When this pin goes low, hard power-down is enabled. This turns off all internal current sinks including the oscillator and the input pins are disconnected from the outside world. On the rising edge, the module is reset.
IRQan interrupt pin that can alert the microcontroller when RFID tag comes into its vicinity.
MISO / SCL / Txacts as Master-In-Slave-Out when SPI interface is enabled, acts as serial clock when I2C interface is enabled and acts as serial data output when UART interface is enabled.
MOSI(Master Out Slave In) is SPI input to the RC522 module.
SCK (Serial Clock) accepts clock pulses provided by the SPI bus Master i.e. Arduino.
SS / SDA / Rxacts as Signal input when SPI interface is enabled, acts as serial data when I2C interface is enabled and acts as serial data input when UART interface is enabled. This pin is usually marked by encasing the pin in a square so it can be used as a reference for identifying the other pins.

Useful notes

  1. LED long leg is positive (anode), it will connect to power; the short leg is negative (cathode) and will connect to ground.
  2. If your Arduino board is connected to a battery or computer via USB, unplug it before building the circuit!
  3. The resistor converts some of the electrical energy into heat. If you put a resistor in series with a LED, the resistor will receive less energy. Without the resistor, a LED would be brighter for a few moments, but quickly burn out.

Wiring

Wiring - MFRC522 RFID Reader with Arduino Tutorial | Acoptex.com
Scematics - MFRC522 RFID Reader with Arduino Tutorial | Acoptex.com

1. Connect VCC pin on the module to 3.3V on the Arduino and GND pin to ground.

2.The pin RST can be connected to any digital pin on the Arduino. In our case, it’s connected to digital pin 5.

3.The IRQ pin is left unconnected as the Arduino library we are going to use doesn’t support it.

4.The rest of the pins are used for SPI communication. As RC522 module require a lot of data transfer, they will give the best performance when connected up to the hardware SPI pins on a microcontroller. The hardware SPI pins are much faster than ‘bit-banging’ the interface code using another set of pins. Each Arduino Board has different SPI pins which should be connected accordingly. For Arduino boards such as the UNO/Nano V3.0 those pins are digital 13 (SCK), 12 (MISO), 11 (MOSI) and 10 (SS). If you have a Mega, the pins are different! You’ll want to use digital 50 (MISO), 51 (MOSI), 52 (SCK), and 53 (SS). Refer below table for quick understanding.

Arduino board / PinsMOSIMISOSCKCS
Arduino Uno11121310
Arduino Nano11121310
Arduino Mega51505253

5. Connect LED’s cathode through resistor 220 Ohm to the ground. Connect the LED’s anode to the digital pin 7.

6.In case you’re using different Arduino board than mentioned above, it is advisable to check the Arduino official documentation before proceeding.

Please note that:

*On the Arduino board many of the pins are not swappable. Because this device uses the SPI bus, who’s pins cannot be moved around, digital pins 11, 12, 13 must remain as shown. RST and IRQ are user specified.

*This device is NOT a 5 volt powered device. You MUST power it with 3.3 volts. If you do not, you risk overheating the RFID module. Most Arduino boards include a 3.3V supply pin which can be used to power the RFID module. 

Step by Step instruction

  1. Do wiring.
  2. Install the RFID library
  3. Plug your Adruino Uno board into your PC and select the correct board and com port.
  4. Verify and upload sketch.
  5. Open the Arduino Serial Monitor and set your baud to 9600 baud.
  6. Scan your card, you will see a bunch of numbers pop out. You will see the message in Arduino Serial Monitor Not allowed as your card is new.
  7. Copy only the number and paste it to the column after “int cards[][5] = { ” – replace with your card number or numbers, space them with ‘,’ for example my cards were: 0 64 134 25 223 and 213 229 89 190 215}. You can add many cards here.
  8. Try to scan again and you will see that the LED is ON and the message in the Arduino Serial Monitor Welcome.

Wrapping up

We have learned about about the RFID RC522 module and how to use it with Arduino board.

Thank you for reading!

Check for more DIY projects on Acoptex.lt and Acoptex.com!

If you are looking for high quality PCBs PCBWay is the best choice: