Arduino Projects

Arduino Project: PN532 NFC RFID Module with Arduino Tutorial for Beginners

Description:

In this tutorial, I will show you how to use the PN532 NFC RFID module with Arduino. This article is geared towards beginners, so I will do my best to explain everything as clearly as possible. I want to make this article easy to understand, so if you have any questions or suggestions, feel free to comment below and I will do my best to answer them quickly.

In addition, I will be comparing the PN532 NFC RFID module with the popular MFRC522 module and discussing the differences between the two. I’ll provide you with the technical specifications of the PN532 module, which will help you decide which one to use for your project. Finally, I’ll demonstrate how to connect the PN532 NFC RFID module to an Arduino and write basic programs to control an LED using UART, I2C, and SPI communication modes. if you want to learn how to interface and control electric door lock and leds then read my article about the RFID rc522 module. So, let’s get started without any delay!




Amazon Links:

Arduino nano

Arduino Uno

pn532 nfc rfid module

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

What is NFC?

NFC is an abbreviation for “Near Field Communication”, which means short-range wireless communication. It is a communication standard that uses a contactless IC chip to communicate simply by holding it up. It features a short communication area, and is a technology used in smartphones with a wallet function and transportation ICs such as Suica and PASMO.

Today, it can be said that it is one of the essential technologies for improving the convenience of our lives. In recent years, NFC-equipped credit cards have also appeared, and the applications of NFC are expanding, such as making payments simply by holding the card over a payment terminal.



How NFC works:

NFC (Near Field Communication) is a wireless communication technology that allows for the transfer of data between two devices in close proximity, typically within a few centimeters. It is a form of RFID (Radio Frequency Identification) technology that operates at a frequency of 13.56 MHz.

NFC technology uses a combination of magnetic field induction and radio frequency identification to enable communication between devices. When two devices come close to each other, they create a magnetic field that allows them to communicate and exchange information.

NFC is used in a variety of applications, such as mobile payments, ticketing, and access control. For example, you can use your NFC-enabled smartphone to make payments at a store or to enter a building by tapping it against an NFC reader.

NFC can also be used for data transfer between two devices. For instance, you can share photos or videos between two NFC-enabled smartphones by tapping them together.

To use NFC, both devices must have an NFC chip and antenna. The NFC chip sends and receives data, while the antenna enables communication by creating the magnetic field. When two devices come close to each other, they establish a connection and exchange data.

Overall, NFC technology is a fast, secure, and convenient way to transfer data and make payments, and it has a wide range of applications in various industries.

Difference between NFC and RFID

RFID (Radio Frequency Identification) and NFC (Near Field Communication) are both wireless communication technologies that are used to transfer data between two devices. While they share some similarities, there are also significant differences between the two.

RFID is a technology that uses radio waves to identify objects and track them. RFID tags are passive devices that contain an antenna and a small chip that stores data. These tags are scanned by RFID readers, which emit radio waves and receive signals back from the tag. RFID technology is widely used in logistics, inventory management, and supply chain management.

NFC is a subset of RFID technology and operates at a shorter range. It is designed for use in mobile devices such as smartphones and is used to enable contactless payments, ticketing, and access control. Unlike RFID tags, NFC tags can be read and written to, allowing for more dynamic interactions between devices.

The main difference between RFID and NFC lies in their communication range and the type of data they can transfer. RFID operates over a longer range than NFC and is primarily used for tracking and identification purposes. In contrast, NFC operates over a much shorter range and is used for communication between devices in close proximity. NFC is also capable of transferring more complex data such as contact information, URLs, and even small amounts of data.

In summary, RFID and NFC are both wireless communication technologies that are used to transfer data between devices. RFID operates over a longer range and is used primarily for tracking and identification, while NFC operates over a shorter range and is used for contactless payments, ticketing, and access control.



Applications of NFC

NFC technology has become increasingly popular in recent years due to its versatility and ease of use. Here are some of the main applications of NFC:

  • Mobile payments: NFC technology enables mobile payment systems, such as Apple Pay and Google Wallet, allowing users to make secure payments by simply tapping their phone on a payment terminal.
  • Access control: NFC is commonly used for access control in buildings, allowing employees to tap their ID card or phone on a reader to gain entry.
  • Transport ticketing: NFC technology can also be used for contactless transport ticketing, allowing users to simply tap their phone or card to pay for their fare.
  • Smart retail: Retailers are starting to use NFC to enhance the shopping experience, such as using NFC-enabled displays to provide customers with more product information or to make purchases directly from the display.
  • Health care: NFC can be used for medical applications, such as storing and transmitting patient data or for tracking and managing medical equipment.
  • Advertising: NFC technology is also used in advertising, allowing users to tap their phone on an NFC-enabled poster or billboard to receive promotional offers or access further information.
  • Gaming: NFC technology has been used in gaming to enhance the user experience, such as using NFC-enabled figurines or cards to unlock additional content or features.
  • Social networking: NFC can also be used for social networking, such as exchanging contact information between devices or for sharing content such as photos or videos.

PN532 NFC RFID Vs MFRC522 RFID Module:

PN532 NFC RFID Module and mfrc522 rfid module comparison

To begin, let’s compare the PN532 NFC RFID module with the popular MFRC522 RFID module that I have been using for a long time.



MFRC522 RFID Module:

The MFRC522 NFC RFID module is a popular and widely used RFID module that operates at a frequency of 13.56 MHz. It is capable of reading and writing data to RFID cards or tags and can communicate with a microcontroller via SPI interface. This module is commonly used in various applications such as access control systems, inventory management, and payment systems.

The MFRC522 NFC module contains an integrated circuit that can demodulate and decode signals from RFID tags or cards. It can also transmit signals to RFID tags or cards to write data or commands. The module has a range of up to 10 cm, making it suitable for short-range applications.

The MFRC522 module has a built-in antenna and can support multiple communication modes such as ISO/IEC 14443 Type A and Type B protocols. It also has a built-in cryptographic engine that can handle authentication and encryption of data transmitted between the RFID tag/card and the reader.

In addition to its technical capabilities, the MFRC522 module is also relatively inexpensive and easy to use. It has become a popular choice for hobbyists and professionals alike who need a reliable and versatile RFID module for their projects.

PN532 NFC RFID Module

The PN532 NFC RFID module is another widely used RFID module that operates at a frequency of 13.56 MHz. Like the MFRC522 NFC module, it can communicate with a microcontroller via SPI interface, but it can also use I2C and UART interfaces. The PN532 NFC module has a range of up to 7 cm, making it suitable for short-range applications.

One of the key features of the PN532 module is its ability to support multiple communication modes and protocols such as ISO/IEC 14443 Type A and Type B, Felica, and NFC Forum Tag Type 2. It also has a built-in cryptographic engine that can handle authentication and encryption of data transmitted between the RFID tag/card and the reader.

The PN532 module has a built-in antenna and can be used with external antennas for increased range. It also has several advanced features such as automatic antenna tuning, signal amplification, and signal modulation. These features make the PN532 NFC module suitable for a wide range of applications, including access control systems, payment systems, and public transportation.

In addition to its technical capabilities, the PN532 module is also relatively easy to use, with libraries available for popular microcontrollers such as Arduino and Raspberry Pi. Its versatility and advanced features make it a popular choice for professionals and hobbyists alike who need a reliable and flexible RFID module for their projects.

RFID (Radio Frequency Identification) technology has become very popular in various applications such as access control, inventory management, and tracking systems. Two commonly used RFID modules are PN532 and MFRC522. Here are some points that describe the differences between the two modules:




PN532 NFC RFID Module:

  • Supports various communication protocols such as I2C, SPI, HSU (High-Speed UART), and NFC (Near Field Communication).
  • Supports three operating modes: reader/writer mode, P2P mode, and card emulation mode.
  • Can read and write various types of RFID tags such as MIFARE, FeliCa, and ISO/IEC 14443 Type A and B.
  • Supports up to 424 kbps data rate.
  • Has a built-in voltage regulator that supports 3.3V and 5V power supply.
  • Has an integrated PCB antenna.
  • Has a maximum operating distance of up to 10 cm.

MFRC522 NFC RFID Module:

  • Supports SPI communication protocol.
  • Supports only reader/writer mode.
  • Can read and write MIFARE Classic tags and some compatible tags.
  • Supports up to 10 Mbps data rate.
  • Requires a separate voltage regulator to support 3.3V power supply.
  • Has an external antenna that can be replaced with a different one for better performance.
  • Has a maximum operating distance of up to 5 cm.

In summary, PN532 NFC module is more versatile and can support various communication protocols and operating modes, while MFRC522 is more specialized and supports only one communication protocol and one operating mode. However, MFRC522 can achieve a higher data rate than PN532, and its external antenna can be replaced for better performance.

PN532 NFC Technical Specifications

The PN532 NFC Module is a versatile RFID module that can support multiple communication protocols and operating modes. Here are some technical specifications of the PN532 module:

  • Communication Protocols: The PN532 supports various communication protocols such as I2C, SPI, HSU (High-Speed UART), and NFC (Near Field Communication).
  • Operating Modes: The module supports three operating modes: reader/writer mode, P2P mode, and card emulation mode.
  • RFID Tag Support: The PN532 can read and write various types of RFID tags such as MIFARE, FeliCa, and ISO/IEC 14443 Type A and B.
  • Data Rate: The module can support data rates of up to 424 kbps.
  • Power Supply: The PN532 has a built-in voltage regulator that supports 3.3V and 5V power supply.
  • Antenna: The module has an integrated PCB antenna that supports a maximum operating distance of up to 10 cm.
  • Dimensions: The PN532 module has dimensions of 45mm x 38mm x 5mm.
  • Operating Temperature: The module can operate in temperatures ranging from -25°C to +85°C.
  • Input/Output: The PN532 module has 7 input/output pins that can be used for communication and control purposes.
  • Security Features: The module has built-in security features such as a unique identifier for each device and encryption/decryption support for secure data transfer.

Overall, the PN532 is a versatile and powerful RFID module that can support multiple communication protocols and operating modes, making it suitable for a wide range of applications in the fields of access control, inventory management, and tracking systems.



PN532 NFC RFID Module V3 Pinout

PN532 NFC RFID Module pinout

The PN532 NFC RFID Module V3 is a popular RFID module used for various applications such as access control, inventory management, and tracking systems. Here are some points that describe the pinout of the PN532 RFID Module V3:

  • VCC: This pin is used to supply power to the module and should be connected to a 3.3V or 5V power source.
  • GND: This pin is the ground pin and should be connected to the ground of the power source.
  • SDA: This pin is used for data transfer in I2C communication mode.
  • SCL: This pin is used for clock signal in I2C communication mode.
  • MOSI: This pin is used for data transfer in SPI communication mode.
  • MISO: This pin is used for data transfer in SPI communication mode.
  • SCK: This pin is used for clock signal in SPI communication mode.
  • NSS: This pin is used for slave select in SPI communication mode.
  • TXD: This pin is used for data transfer in HSU (High-Speed UART) communication mode.
  • RXD: This pin is used for data transfer in HSU (High-Speed UART) communication mode.
  • IRQ: This pin is an interrupt pin that can be used to signal events such as the detection of an RFID tag.
  • SEL0 and SEL1: These pins are used to select the operating mode of the module.
  • RESET: This pin is used to reset the module.

PN532 NFC RFID Module uart, hus, i2c and spi interface

The board comes equipped with a built-in level shifter and uses a standard 5V TTL for I2C and UART, as well as a 3.3V TTL for SPI. However, it is important to note that the I2C and HSU (High-Speed UART) share the same pins.

The default mode of the module is set to HSU, but you can change the interface by using the toggle switches provided. In the following explanation, I will guide you through the usage of all three modes, starting with the default HSU mode.



PN532 NFC RFID UART Circuit Diagram:

PN532 NFC RFID Module uart connection with Arduino

To get started with the PN532 NFC RFID module, you need to connect the VCC and GND pins of the module to the 5V and GND pins of the Arduino board, respectively. Additionally, you should connect the TX and RX pins of the module to the D2 and D3 pins of the Arduino board.

Furthermore, two LEDs should be connected to the Arduino pins 5 and 6. These minimal connections are enough to get started with the module. If you need to power up your Arduino board externally, you can use a 5V regulated power supply based on the LM7805 voltage regulator. Alternatively, you can use your laptop to power up the Arduino.

test uart and serial mode of PN532 NFC RFID Module using Arduino

I am using an Arduino Nano development board and have connected the LEDs and PN532 RFID module according to the circuit diagram. If you want to use the HSU High-Speed UART mode, you don’t need to change the position of the toggle switches since it is set to UART mode by default.

Regardless of whether you choose to start with HSU, I2C, or SPI, the first step is to download all the required libraries.

Download PN532 RFID Module Library

To access the folder, download the WinRAR file and extract its contents. Once you have extracted the files, navigate to the folder and double-click to open it.

PN532 NFC RFID Module Arduino library

Upon opening the folder, you will find all the required libraries inside. To add these libraries to your Arduino IDE, copy the folders and paste them into the Arduino libraries folder.



PN532 NFC RFID UART Programming:

The above code is written for the HSU mode and utilizes pins 3 and 2. The LEDs are connected to the Arduino pins 5 and 6. You can also use this code to find the IDs of RFID tags. To do so, open the Serial Monitor and start scanning your RFID tags.

Similarly, I was able to obtain the UID of the card using a similar method.

By utilizing these IDs in programming, you can control certain things. In my case, I am using them to control two LEDs. I have already uploaded this program, so let’s see the PN532 NFC RFID module HSU mode in action.

use uart mode of PN532 NFC RFID Module to controle load using Arduino

Now, using the RFID Key Chain Tag.

how to control load using PN532 NFC RFID Module key chain tag with Arduino




PN532 RFID I2C Circuit Diagram:

PN532 NFC RFID Module i2c Arduino circuit diagram

As I mentioned before, the HSU and I2C modes share the same pins. For this mode, you will see that the SDA and SCL pins of the PN532 RFID module are connected to the Arduino A4 and A5 pins, respectively. Other connections remain unchanged.

PN532 NFC RFID Module mode change from spi to i2c

In this setup, the SDA and SCL pins of the PN532 RFID module are connected to the Arduino A4 and A5 pins, respectively. As I am using the I2C mode this time, I have turned on channel 1.

PN532 RFID I2C Programming:

For this setup, I have included the I2C library in the program. I have already uploaded this program, so let’s see the PN532 RFID Module I2C mode in action.

PN532 NFC RFID Module i2c mode testing using Arduino

With great success, I have managed to control two captivating LEDs using the RFID card and keychain tag. Now, let’s move forward and delve into the stimulating world of the SPI mode.



PN532 NFC RFID SPI Circuit Diagram:

PN532 NFC RFID Module spi Arduino circuit diagram

If you aspire to operate the PN532 NFC RFID module using the SPI mode, you must connect SCK to Arduino pin 13, MISO to pin 12, MOSI to pin 11, SS to pin 10, and RST0 to pin 9. With this, all other connections shall remain intact. As per the circuit diagram, I have linked the PN532 RFID module SPI pins to the Arduino.

PN532 NFC RFID Module with Arduino spi mode activiting

To activate the thrilling SPI mode on the PN532 NFC RFID module, you must first turn off the first channel and then toggle the switch to the exhilarating second channel. This will unleash the full power of SPI, allowing you to communicate with the module through the Arduino’s pins 10, 11, 12, 13, and 9, which are now connected to the module’s SS, MOSI, MISO, SCK, and RST0 pins respectively.



PN532 NFC RFID SPI Programming:

This time, I have incorporated the SPI library for the PN532 RFID module. As you can observe, the wiring setup is identical to the previous one with the exception of connecting SCK, MISO, MOSI, SS, and RST0 to the respective Arduino pins 13, 12, 11, 10, and 9.

To activate the SPI mode of the PN532 NFC RFID module, you need to toggle OFF the channel 1 and turn ON the channel 2.

With the SPI mode enabled, I have uploaded the code and now we can witness the PN532 NFC RFID Module SPI mode in action.

testing PN532 NFC RFID Module spi mode using Arduino

Marvelous work! With this, you have learned how to use the PN532 NFC RFID module with an Arduino board and how to use all three interfaces or modes: UART, I2C, and SPI. You were able to successfully control two LEDs using an RFID key chain tag and an RFID card tag. Now you can expand your knowledge and skills to create more advanced projects using the PN532 NFC RFID module with the Arduino.



PN532 NFC RFID module advantages:

The PN532 NFC RFID module is a popular choice for developers and users due to its many advantages. Here are some of its key advantages summarized in points:

  • Versatility: The PN532 NFC module is compatible with a wide range of NFC and RFID protocols, making it versatile for a variety of applications.
  • Easy Integration: The module comes with an easy-to-use interface and API, making it simple to integrate into projects.
  • Secure Communication: The PN532 NFC module uses advanced encryption algorithms to ensure secure communication between the reader and the tag.
  • High-Performance: The module offers high-speed data transfer and reading capabilities, making it an efficient solution for data-intensive applications.
  • Low Power Consumption: The PN532 module is designed to consume low power, making it ideal for battery-powered devices.
  • Compact Size: The module is small in size, making it easy to integrate into small devices.
  • Cost-effective: The PN532 module is an affordable solution for NFC and RFID applications, making it accessible to a wide range of users.
  • Long-Range: The module has a long read range, making it ideal for use in applications such as access control and ticketing systems.
  • User-Friendly: The module is user-friendly and can be easily programmed to read and write data from NFC and RFID tags.

PN532 NFC RFID module disadvantages:

While the PN532 NFC RFID module offers many advantages, there are also some potential disadvantages to consider:

  • Limited Range: While the PN532 module has a long read range, it may not be sufficient for some applications that require a greater distance between the reader and the tag.
  • Limited Compatibility: Although the PN532 module is compatible with many NFC and RFID protocols, there may be some protocols that are not supported, limiting its compatibility with certain devices.
  • Limited Memory: The module has limited memory capacity, which can be a limitation for applications that require storing large amounts of data.
  • Limited Support: Although the PN532 module is widely used, there may be limited support and resources available in certain regions or for certain applications.
  • Complex Configuration: Configuring the PN532 module can be complex for inexperienced users, which may require additional time and resources to properly set up.
  • Limited Functionality: While the module offers many useful features, it may not have all the functionality required for certain specialized applications.
  • Vulnerability to Interference: The PN532 module may be vulnerable to interference from other devices, which can affect its performance and reliability.




MFRC522 RFID module advantages

The MFRC522 RFID module is a popular choice for developers and users due to its many advantages. Here are some of its key advantages summarized in points:

  • Versatility: The MFRC522 module is compatible with a wide range of RFID protocols, making it versatile for a variety of applications.
  • Easy Integration: The module comes with an easy-to-use interface and API, making it simple to integrate into projects.
  • High-Performance: The module offers high-speed data transfer and reading capabilities, making it an efficient solution for data-intensive applications.
  • Low Power Consumption: The MFRC522 module is designed to consume low power, making it ideal for battery-powered devices.
  • Cost-effective: The MFRC522 module is an affordable solution for RFID applications, making it accessible to a wide range of users.
  • Compact Size: The module is small in size, making it easy to integrate into small devices.
  • Secure Communication: The MFRC522 module uses advanced encryption algorithms to ensure secure communication between the reader and the tag.
  • User-Friendly: The module is user-friendly and can be easily programmed to read and write data from RFID tags.
  • Large Memory: The module has a large memory capacity, which allows it to store large amounts of data.

MFRC522 RFID module disadvantages

While the MFRC522 RFID module offers many advantages, there are also some potential disadvantages to consider:

  • Limited Range: The MFRC522 module has a limited read range, which can be a limitation for applications that require a greater distance between the reader and the tag.
  • Limited Compatibility: Although the MFRC522 module is compatible with many RFID protocols, there may be some protocols that are not supported, limiting its compatibility with certain devices.
  • Vulnerability to Interference: The MFRC522 module may be vulnerable to interference from other devices, which can affect its performance and reliability.
  • Limited Functionality: While the module offers many useful features, it may not have all the functionality required for certain specialized applications.
  • Limited Support: Although the MFRC522 module is widely used, there may be limited support and resources available in certain regions or for certain applications.
  • Complex Configuration: Configuring the MFRC522 module can be complex for inexperienced users, which may require additional time and resources to properly set up.
  • Limited Memory: While the module has a large memory capacity, there may be some applications that require even more memory, making the MFRC522 module insufficient.

Related Articles

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button