Back to Explorer

esp32-NFC-PN532-13-56MHz

Project Information

Author

Mikrobot.pl

Board

ESP32 Dev Module

SDK Version

3.3.5

Platform

ESP32

Created

Updated

Description

Reads NFC tag UID (13.56 MHz) and prints data to the Serial Monitor using MOSI/MISO/SCK instead of I2C.

Flash to Device

Login required: You need to login or create an account to flash this project.

Sorry, your browser doesn't support Web Serial.Web Serial requires HTTPS.

README

PN532 NFC Reader (SPI) โ€“ ESP32

Read NFC / RFID tags via PN532 (13.56 MHz) using SPI and display data in Serial Monitor

This project demonstrates how to use an ESP32 with an PN532 NFC reader in SPI mode to detect NFC / RFID tags and print their UID data to the Serial Monitor.

The PN532 communicates with the ESP32 using MOSI, MISO, SCK and CS pins (SPI), not I2C. The sketch initializes the PN532, verifies the firmware version, and continuously waits for NFC tags in range.


โญ Features

  • ๐Ÿ“ก PN532 NFC reader (13.56 MHz)

  • ๐Ÿ” SPI communication (MOSI / MISO / SCK / CS)

  • ๐Ÿ†” Reads NFC tag UID

    • MIFARE Classic
    • MIFARE Ultralight
    • NTAG / ISO14443A
  • ๐Ÿ–ฅ Serial Monitor output

  • โšก Works with ESP32 Dev Module

  • ๐Ÿงช Firmware detection for easy debugging


๐Ÿ“ฆ Hardware Requirements

  • ESP32 (ESP32 Dev Module / ESP32-WROOM)
  • PN532 NFC reader module (SPI-capable)
  • NFC cards or tags (13.56 MHz)
  • Jumper wires

๐Ÿ”Œ Wiring (SPI)

PN532 ESP32
VCC 3.3V
GND GND
SCK GPIO18
MISO GPIO19
MOSI GPIO23
SS / CS GPIO5

โš ๏ธ Important PN532 must be powered with 3.3V when used with ESP32.


๐Ÿ”ง PN532 Interface Selection

The PN532 supports multiple communication modes:

  • I2C
  • SPI
  • HSU (UART)

โœ… SPI Mode (required)

Most PN532 modules use DIP switches or solder jumpers to select the interface.

Typical configuration for SPI:

SW1 = OFF
SW2 = ON
  • Switch UP โ†’ ON
  • Switch DOWN โ†’ OFF

After changing switches, disconnect and reconnect power to the PN532.


๐Ÿ”ง Software Requirements

  • Arduino IDE

  • ESP32 board package

    Boards Manager โ†’ esp32 by Espressif Systems
    

Required Libraries

Install via Arduino Library Manager:

  • Adafruit PN532

Core libraries used:

  • SPI
  • WiFi (ESP32 core dependency)

๐Ÿš€ Getting Started

  1. Open the sketch in Arduino IDE

  2. Select your board:

    ESP32 Dev Module
    
  3. Select the correct COM port

  4. Upload the sketch

  5. Open Serial Monitor

  6. Set baud rate to:

    115200
    

๐Ÿ“ถ Usage

  1. Power the ESP32 and PN532
  2. Open the Serial Monitor
  3. Bring an NFC card or tag close to the reader
  4. The UID will be printed:
NFC card detected!
UID Length: 4 bytes
UID Value: 04 A1 B2 C3

๐Ÿงช Debugging Tips

  • If nothing appears in Serial Monitor:

    • Check baud rate (115200)
    • Check COM port
    • Verify PN532 is in SPI mode
    • Ensure CS pin is HIGH before initialization
    • Confirm 3.3V power, not 5V
  • If firmware version is not detected:

    • Recheck DIP switch orientation
    • Shorten SPI wires
    • Power-cycle PN532

๐Ÿ›  Customization Ideas

You can extend this project by adding:

  • ๐Ÿ“– Reading MIFARE Classic blocks
  • โœ๏ธ Writing data to NFC tags
  • ๐Ÿงพ JSON output over Serial
  • ๐ŸŒ Sending NFC data over WiFi / MQTT
  • ๐Ÿ”˜ Button-triggered scans
  • ๐Ÿ”’ Access control systems

๐Ÿ“„ License

This project is released under the MIT License.

You are free to use, modify, and distribute it for personal and commercial projects.