PN532 NFC Module

View on Amazon
Overview
About PN532 NFC Module
The PN532 is a widely used NFC and RFID module, offering reliable wireless data exchange for various applications.
⚡ Key Features
- Multi-Protocol Support – Works with ISO/IEC 14443 Type A & B cards and NFC peer-to-peer communication.
- Flexible Interfaces – Supports I2C, SPI, and UART, ensuring easy integration.
- Versatile Applications – Ideal for access control, contactless payments, smart authentication, and data exchange.
- Compact & Efficient – Low power consumption with a high-performance NFC controller.
Get Your PN532
Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.
PN532 Specifications
Complete technical specification details for PN532 NFC Module
📊 Technical Parameters
PN532 Pinout
The PN532 is a versatile NFC controller supporting multiple communication protocols: I²C, SPI, and HSU (High-Speed UART). Select the mode using onboard switches (Switch 1: ON + Switch 2: OFF = I²C | Switch 1: OFF + Switch 2: ON = SPI | Both OFF = UART).
Visual Pinout Diagram

Pin Types
Quick Tips
I²C Mode: Switch 1 ON, Switch 2 OFF - Uses SDA/SCL pins (address 0x24),⚡ SPI Mode: Switch 1 OFF, Switch 2 ON - Uses MISO/MOSI/SCK/SS pins (fastest)
UART Mode: Both switches OFF - SDA becomes TX, SCL becomes RX,⚠️ Choose only ONE communication mode at a time by setting switches correctly
IRQ and RSTO pins are optional but recommended for advanced applications,🔌 The module auto-detects 3.3V or 5V operation
Pin Descriptions
| Pin Name | Type | Description | Notes |
|---|---|---|---|
1 VCC | Power | Power supply (3.3V or 5V) - pin 1 | Works with both 3.3V and 5V logic levels |
2 VCC | Power | Power supply (3.3V or 5V) - pin 2 | Both VCC pins should be connected for stable power |
3 GND | Power | Ground connection (pin 1) | Connect to ESP32 ground |
4 GND | Power | Ground connection (pin 2) | Both GND pins should be connected for stability |
5 SDA | Communication | I²C Data / UART TX (mode-dependent) | I²C mode = Data line | UART mode = TX to ESP32 RX |
6 SCL | Communication | I²C Clock / UART RX (mode-dependent) | I²C mode = Clock line | UART mode = RX from ESP32 TX |
7 MISO | Communication | SPI Master In Slave Out | Used only in SPI mode |
8 MOSI | Communication | SPI Master Out Slave In | Used only in SPI mode |
9 SCK | Communication | SPI Serial Clock | Used only in SPI mode |
10 SS (NSS) | Communication | SPI Slave Select / Chip Select | Used only in SPI mode |
11 IRQ | Control | Interrupt output (optional) | Triggers when NFC event occurs - can improve efficiency |
12 RSTO | Control | Reset control (optional) | Hardware reset for the module |
Premium 3D Printed Enclosure
Protect your PN532 sensor with a custom-designed 3D printed enclosure. Professional quality, perfect fit, and ready to use.
Perfect Fit
Custom designed
Premium Quality
High-grade materials
Durable
Long-lasting protection
Quick Setup
Easy to install
Each enclosure is carefully designed and tested to ensure perfect fit and functionality. Made with premium materials for durability and aesthetics.
Wiring PN532 to ESP32
In SPI (Serial Peripheral Interface) mode, the PN532 NFC module communicates with the ESP32 using fast, synchronous data exchange. This mode is ideal for high-speed applications requiring stable communication. Set switches: Switch 1 OFF, Switch 2 ON.
Visual Wiring Diagram

Connection Status
Protocol
Pin Connections
| PN532 Pin | Connection | ESP32 Pin | Description |
|---|---|---|---|
1 VCC Required | 3.3V | Power supply pin | |
2 GND Required | GND | Ground connection (connect both GND pins) | |
3 MISO Required | GPIO19 | SPI Master In Slave Out | |
4 MOSI Required | GPIO23 | SPI Master Out Slave In | |
5 SCK Required | GPIO18 | SPI Serial Clock | |
6 SS (NSS) Required | GPIO5 | SPI Chip Select / Slave Select | |
7 IRQ Optional | GPIO4 | Interrupt output for NFC events | |
8 RSTO Optional | GPIO21 | Hardware reset control |
SPI mode provides the fastest communication speed compared to I²C and UART
Set Switch 1 to OFF and Switch 2 to ON for SPI mode before powering up
Connect both VCC pins and both GND pins for stable power delivery
IRQ pin can improve efficiency by eliminating polling - highly recommended
More Wiring Options
Alternative Wiring #1
In I²C (Inter-Integrated Circuit) mode, the PN532 NFC module communicates with the ESP32 using a simple two-wire interface. This mode requires fewer connections than SPI and allows multiple devices on the same bus. Set switches: Switch 1 ON, Switch 2 OFF.

Connection Status
Protocol
I2CPin Connections - Option 3
| PN532 Pin | Connection | ESP32 Pin | Description |
|---|---|---|---|
1 VCC Required | 3.3V | Power supply pin | |
2 GND Required | GND | Ground connection (connect both GND pins) | |
3 SDA Required | GPIO21 | I²C Data line (default ESP32 SDA) | |
4 SCL Required | GPIO22 | I²C Clock line (default ESP32 SCL) | |
5 IRQ Optional | GPIO4 | Interrupt output for NFC events | |
6 RSTO Optional | GPIO5 | Hardware reset control |
I²C mode uses only two data lines (SDA & SCL) - ideal for minimal wiring
Set Switch 1 to ON and Switch 2 to OFF for I²C mode (address 0x24)
Multiple I²C devices can share the same bus with different addresses
Pull-up resistors (4.7kΩ) on SDA/SCL are usually built-in on ESP32
Alternative Wiring #2
In HSU (High-Speed UART) mode, the PN532 NFC module communicates with the ESP32 using standard serial UART interface. This mode is simple and widely supported across microcontrollers. Set switches: Both switches OFF.

Connection Status
Protocol
UARTPin Connections - Option 4
| PN532 Pin | Connection | ESP32 Pin | Description |
|---|---|---|---|
1 VCC Required | 3.3V | Power supply pin | |
2 GND Required | GND | Ground connection (connect both GND pins) | |
3 SDA (TX) Required | GPIO16 | UART TX from PN532 to ESP32 RX | |
4 SCL (RX) Required | GPIO17 | UART RX from ESP32 TX to PN532 | |
5 IRQ Optional | GPIO4 | Interrupt output for NFC events | |
6 RSTO Optional | GPIO5 | Hardware reset control |
UART mode provides standard serial communication - widely compatible
Set both switches to OFF for HSU (UART) mode
High-speed data transfer suitable for real-time NFC applications
SDA pin becomes TX, SCL pin becomes RX in UART mode
PN532 Troubleshooting
Common issues and solutions to help you get your sensor working
Common Issues
Issue: The PN532 module does not power up or respond to commands.
Possible causes include insufficient power supply, incorrect wiring, or faulty hardware.
Solution: Ensure the module is connected to a stable power source within the recommended voltage range of 3.3V to 5V. Verify that all connections are secure and correctly configured. If the problem persists, consider testing the module with a different power source or replacing it.
Issue: The module fails to communicate with the microcontroller over the chosen interface (I2C, SPI, or UART).
Possible causes include incorrect wiring, improper interface selection, or incompatible voltage levels.
Solution: Double-check the wiring to ensure correct connections for the chosen interface. For I2C, ensure that the SDA and SCL lines are properly connected, and for SPI, verify the MOSI, MISO, SCK, and SS lines. If using I2C, ensure that pull-up resistors are present on the SDA and SCL lines.
Issue: The module initializes correctly but fails to read NFC or RFID tags.
Possible causes include incorrect antenna orientation, insufficient power supply, or interference from nearby electronic devices.
Solution: Ensure the module's antenna is properly oriented and positioned near the tags. Verify that the power supply provides adequate current for the module's operation. Keep the module away from sources of electromagnetic interference.
Issue: The module detects tags intermittently or with delays.
Possible causes include low-quality tags, environmental interference, or firmware issues.
Solution: Test with different tags to rule out tag quality issues. Ensure the operating environment is free from strong electromagnetic interference. Update the module's firmware to the latest version to benefit from bug fixes and improvements.
Issue: The module operates erratically or produces errors during operation.
Possible causes include outdated or incompatible libraries, incorrect initialization, or software bugs.
Solution: Ensure that the latest version of the PN532 library is installed and compatible with your development environment. Review the initialization code to confirm that the module is set up correctly. Consult the module's documentation and community forums for guidance on proper usage.
Debugging Tips
Use the Serial Monitor to check for error messages and verify the sensor's output. Add debug prints in your code to track the sensor's state.
Use a multimeter to verify voltage levels and check for continuity in your connections. Ensure the power supply is stable and within the sensor's requirements.
Additional Resources
PN532 Programming Examples
Ready-to-use code examples for different platforms and frameworks
#include <Wire.h>
#include <Adafruit_PN532.h>
#define SDA_PIN 21
#define SCL_PIN 22
Adafruit_PN532 nfc(SDA_PIN, SCL_PIN);
void setup() {
Serial.begin(115200);
Serial.println("Initializing PN532...");
nfc.begin();
uint32_t version = nfc.getFirmwareVersion();
if (!version) {
Serial.println("Didn't find PN532 board");
while (1);
}
nfc.SAMConfig();
Serial.println("PN532 initialized!");
}
void loop() {
Serial.println("Waiting for NFC tag...");
uint8_t success;
uint8_t uid[] = {0};
uint8_t uidLength;
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
if (success) {
Serial.print("Found NFC tag with UID: ");
for (uint8_t i = 0; i < uidLength; i++) {
Serial.print(uid[i], HEX);
Serial.print(" ");
}
Serial.println();
}
delay(1000);
}setup function initializes the module, and the firmware version is retrieved for verification. In the loop, the module continuously scans for NFC tags and prints the UID of any detected tag. Additional features, such as writing to tags or handling other NFC modes, can be implemented as needed.#include <stdio.h>
#include <stdlib.h>
#include <esp_log.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "sdkconfig.h"
#include "pn532_driver_i2c.h"
#include "pn532_driver_hsu.h"
#include "pn532.h"
// select ONLY ONE interface for the PN532
#define PN532_MODE_I2C 1
#define PN532_MODE_HSU 0
#define PN532_MODE_SPI 0
#if PN532_MODE_I2C
// I2C mode needs only SDA, SCL and IRQ pins. RESET pin will be used if valid.
// IRQ pin can be used in polling mode or in interrupt mode. Use menuconfig to select mode.
#define SCL_PIN (0)
#define SDA_PIN (1)
#define RESET_PIN (-1)
#define IRQ_PIN (3)
#elif PN532_MODE_HSU
// HSU mode needs only RX/TX pins. RESET pin will be used if valid.
#define RESET_PIN (-1)
#define IRQ_PIN (-1)
#define HSU_HOST_RX (4)
#define HSU_HOST_TX (5)
#define HSU_UART_PORT UART_NUM_1
#define HSU_BAUD_RATE (921600)
#elif PN532_MODE_SPI
#error SPI is not implemented
#endif
static const char *TAG = "ntag_read";
void app_main()
{
pn532_io_t pn532_io;
esp_err_t err;
printf("APP MAIN
");
#if 0
// Enable DEBUG logging
esp_log_level_set("PN532", ESP_LOG_DEBUG);
esp_log_level_set("pn532_driver", ESP_LOG_DEBUG);
esp_log_level_set("pn532_driver_i2c", ESP_LOG_DEBUG);
esp_log_level_set("pn532_driver_hsu", ESP_LOG_DEBUG);
esp_log_level_set("i2c.master", ESP_LOG_DEBUG);
#endif
vTaskDelay(1000 / portTICK_PERIOD_MS);
#if PN532_MODE_I2C
ESP_LOGI(TAG, "init PN532 in I2C mode");
ESP_ERROR_CHECK(pn532_new_driver_i2c(SDA_PIN, SCL_PIN, RESET_PIN, IRQ_PIN, 0, &pn532_io));
#elif PN532_MODE_HSU
ESP_LOGI(TAG, "init PN532 in HSU mode");
ESP_ERROR_CHECK(pn532_new_driver_hsu(HSU_HOST_RX,
HSU_HOST_TX,
RESET_PIN,
IRQ_PIN,
HSU_UART_PORT,
HSU_BAUD_RATE,
&pn532_io));
#endif
do {
err = pn532_init(&pn532_io);
if (err != ESP_OK) {
ESP_LOGW(TAG, "failed to initialize PN532");
pn532_release(&pn532_io);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
} while(err != ESP_OK);
ESP_LOGI(TAG, "get firmware version");
uint32_t version_data = 0;
do {
err = pn532_get_firmware_version(&pn532_io, &version_data);
if (ESP_OK != err) {
ESP_LOGI(TAG, "Didn't find PN53x board");
pn532_reset(&pn532_io);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
} while (ESP_OK != err);
// Log firmware infos
ESP_LOGI(TAG, "Found chip PN5%x", (unsigned int)(version_data >> 24) & 0xFF);
ESP_LOGI(TAG, "Firmware ver. %d.%d", (int)(version_data >> 16) & 0xFF, (int)(version_data >> 8) & 0xFF);
ESP_LOGI(TAG, "Waiting for an ISO14443A Card ...");
while (1)
{
uint8_t uid[] = {0, 0, 0, 0, 0, 0, 0}; // Buffer to store the returned UID
uint8_t uid_length; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
// Wait for an ISO14443A type cards (Mifare, etc.). When one is found
// 'uid' will be populated with the UID, and uid_length will indicate
// if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
err = pn532_read_passive_target_id(&pn532_io, PN532_BRTY_ISO14443A_106KBPS, uid, &uid_length, 0);
if (ESP_OK == err)
{
// Display some basic information about the card
ESP_LOGI(TAG, "
Found an ISO14443A card");
ESP_LOGI(TAG, "UID Length: %d bytes", uid_length);
ESP_LOGI(TAG, "UID Value:");
ESP_LOG_BUFFER_HEX_LEVEL(TAG, uid, uid_length, ESP_LOG_INFO);
err = pn532_in_list_passive_target(&pn532_io);
if (err != ESP_OK) {
ESP_LOGI(TAG, "Failed to inList passive target");
continue;
}
NTAG2XX_MODEL ntag_model = NTAG2XX_UNKNOWN;
err = ntag2xx_get_model(&pn532_io, &ntag_model);
if (err != ESP_OK)
continue;
int page_max;
switch (ntag_model) {
case NTAG2XX_NTAG213:
page_max = 45;
ESP_LOGI(TAG, "found NTAG213 target (or maybe NTAG203)");
break;
case NTAG2XX_NTAG215:
page_max = 135;
ESP_LOGI(TAG, "found NTAG215 target");
break;
case NTAG2XX_NTAG216:
page_max = 231;
ESP_LOGI(TAG, "found NTAG216 target");
break;
default:
ESP_LOGI(TAG, "Found unknown NTAG target!");
continue;
}
for(int page=0; page < page_max; page+=4) {
uint8_t buf[16];
err = ntag2xx_read_page(&pn532_io, page, buf, 16);
if (err == ESP_OK) {
ESP_LOG_BUFFER_HEXDUMP(TAG, buf, 16, ESP_LOG_INFO);
}
else {
ESP_LOGI(TAG, "Failed to read page %d", page);
break;
}
}
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
}# Choose one - SPI or I2C!
# Over SPI
pn532_spi:
cs_pin: D3
update_interval: 1s
binary_sensor:
- platform: pn532
uid: 74-10-37-94
name: "PN532 NFC Tag"
# Over I2C
pn532_i2c:
update_interval: 1s
binary_sensor:
- platform: pn532
uid: 74-10-37-94
name: "PN532 NFC Tag"platformio.ini
[env:pn532]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200main.cpp
#include <Wire.h>
#include <Adafruit_PN532.h>
Adafruit_PN532 nfc(21, 22);
void setup() {
Serial.begin(115200);
nfc.begin();
if (!nfc.getFirmwareVersion()) {
Serial.println("Failed to find PN532!");
while (1);
}
nfc.SAMConfig();
Serial.println("Waiting for NFC tag...");
}
void loop() {
uint8_t uid[7];
uint8_t uidLength;
if (nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength)) {
Serial.print("Found NFC tag with UID: ");
for (uint8_t i = 0; i < uidLength; i++) {
Serial.print(uid[i], HEX);
Serial.print(" ");
}
Serial.println();
}
delay(1000);
}from machine import I2C, Pin
import time
from pn532_i2c import PN532_I2C
# Initialize I2C
i2c = I2C(1, scl=Pin(22), sda=Pin(21))
pn532 = PN532_I2C(i2c, debug=False)
pn532.SAM_configuration()
while True:
print("Waiting for NFC tag...")
uid = pn532.read_passive_target()
if uid:
print("Found NFC tag with UID:", [hex(i) for i in uid])
time.sleep(1)Wrapping Up PN532
The ESP32 PN532 NFC Module is a powerful NFC sensor that offers excellent performance and reliability. With support for multiple development platforms including Arduino, ESP-IDF, ESPHome, PlatformIO, and MicroPython, it's a versatile choice for your IoT projects.
Best Practices
For optimal performance, ensure proper wiring and follow the recommended configuration for your chosen development platform.
Safety First
Always verify power supply requirements and pin connections before powering up your project to avoid potential damage.
Ready to Start Building?
Now that you have all the information you need, it's time to integrate the PN532 into your ESP32 project and bring your ideas to life!








