Getting Started with the PN532 NFC Module
This guide covers everything you need to start using the ELECHOUSE PN532 NFC / RFID Module with Arduino or ESP32. The PN532 is the most widely supported NFC module for makers and embedded developers.
What You Need
- ELECHOUSE PN532 NFC RFID Module V4 (or PN5321 MINI / Evolution V1)
- Arduino UNO / Nano / Mega — or ESP32 development board
- Jumper wires and breadboard
- An NFC card or tag (MIFARE Classic 1K, NTAG213, or similar)
- Arduino IDE with ESP32 board support (if using ESP32)
- ELECHOUSE PN532 library installed
Step 1 — Set the Interface Mode
The PN532 V4 has a DIP switch that selects the communication interface. Set it before wiring:
| Mode |
SW1 |
SW2 |
Best for |
| HSU (UART) |
0 |
0 |
Arduino software serial, simplest wiring |
| I2C |
1 |
0 |
Shared bus, fewer pins |
| SPI |
0 |
1 |
Fastest, most reliable, recommended for ESP32 |
Note: switch numbering may vary by board revision — check the silkscreen.
Step 2 — Wiring
SPI — Arduino UNO
| PN532 Pin |
Arduino Pin |
| VCC |
5V |
| GND |
GND |
| SCK |
D13 |
| MISO |
D12 |
| MOSI |
D11 |
| NSS (CS) |
D10 |
SPI — ESP32
| PN532 Pin |
ESP32 Pin |
| VCC |
3V3 |
| GND |
GND |
| SCK |
GPIO18 |
| MISO |
GPIO19 |
| MOSI |
GPIO23 |
| NSS (CS) |
GPIO5 |
I2C — Arduino UNO
| PN532 Pin |
Arduino Pin |
| VCC |
5V |
| GND |
GND |
| SDA |
A4 |
| SCL |
A5 |
Step 3 — Install the Library
- Open Arduino IDE.
- Go to Sketch → Include Library → Manage Libraries.
- Search for
PN532 and install ELECHOUSE PN532.
- Or download from github.com/elechouse/PN532 and add as a ZIP library.
Step 4 — Upload and Test
#include <PN532.h>
#include <PN532_SPI.h>
PN532_SPI pn532spi(SPI, 10); // SS = 10 for Arduino UNO
// ESP32: PN532_SPI pn532spi(SPI, 5);
PN532 nfc(pn532spi);
void setup() {
Serial.begin(115200);
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if (!versiondata) {
Serial.println("PN532 not found. Check wiring and interface mode switch.");
while (1);
}
Serial.print("Found PN532 firmware version: ");
Serial.println((versiondata >> 16) & 0xFF, DEC);
nfc.SAMConfig();
Serial.println("Waiting for NFC card...");
}
void loop() {
uint8_t uid[7];
uint8_t uidLength;
if (nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength)) {
Serial.print("Card UID: ");
for (uint8_t i = 0; i < uidLength; i++) {
if (uid[i] < 0x10) Serial.print("0");
Serial.print(uid[i], HEX);
Serial.print(" ");
}
Serial.println();
delay(1000); // wait before next read
}
}
Step 5 — Verify
- Open Serial Monitor at 115200 baud.
- You should see:
Found PN532 firmware version: 1
- Tap an NFC card or tag — its UID will print.
Troubleshooting
| Problem |
Likely cause |
Fix |
| PN532 not found |
Wrong interface switch position |
Set DIP switch to match your wiring (SPI/I2C/UART) |
| PN532 not found |
MOSI and MISO swapped |
Swap MISO/MOSI wires |
| No UID printed on card tap |
Wrong library backend |
Confirm PN532_SPI matches your wiring |
| Card detected but UID garbled |
3.3 V / 5 V level mismatch |
Use a level shifter between 5V Arduino and 3.3V module |
| ESP32 not finding module |
Default SPI pins differ |
Explicitly call SPI.begin(18,19,23,5) before nfc.begin() |
Next Steps
Related Pages