Logo

Interfacing NFC Module with Arduino

NFC Module

An NFC (Near Field Communication) module enables short-range wireless communication between devices. With Arduino, you can use it to create secure access systems, contactless payment simulations, or smart automation projects.

Working Principle of NFC Module

The NFC module operates on the principle of electromagnetic induction. It uses a 13.56 MHz frequency to communicate with compatible NFC tags or other devices within a few centimeters. The module reads or writes data by creating an electromagnetic field that powers the passive tag.

Types of NFC Modules

PN532 NFC Module

  • Supports I2C, SPI, and UART interfaces.
  • Can read and write NFC cards or tags.
  • Used in access control, data transfer, and identification projects.

RC522 RFID/NFC Module

  • Operates at 13.56 MHz.
  • Communicates with Arduino using SPI protocol.
  • Reads UID and memory blocks from NFC tags.

Requirements

1. Arduino Uno or compatible board

2. NFC Module (PN532 or RC522)

3. Jumper wires

4. NFC tags/cards

Pin Configuration of NFC Module

PN532 NFC Module (SPI Mode)

  • VCC: Connect to +5V on Arduino.
  • GND: Connect to GND on Arduino.
  • SCK: Connect to pin 13.
  • MOSI: Connect to pin 11.
  • MISO: Connect to pin 12.
  • SS/SDA: Connect to pin 10.

Wiring the NFC Module to Arduino

Connect the VCC and GND pins of the NFC module to 5V and GND on the Arduino. Use SPI pins (MOSI, MISO, SCK, and SS) for data communication. Make sure the module is in SPI mode using the onboard jumpers or switches.

Algorithm

  1. Initialize Components

    • Connect the NFC module to the Arduino using the correct pin configuration.
    • Install necessary libraries like 'Adafruit_PN532' or 'MFRC522'.
  2. Write the Code

    • Include the required library headers.
    • Initialize the NFC module in the setup() function.
    • Read tag UID and display it via Serial Monitor in the loop() function.
  3. Trigger Outputs or Actions

    • Use UID detection to verify known cards.
    • Control relays, LEDs, or motors based on the detected tag.
  4. Test the System

    • Upload the code to the Arduino.
    • Tap NFC tags near the module and observe the serial output or actions performed.

Arduino Code

1#include <Wire.h>
2#include <Adafruit_PN532.h>
3
4// Create NFC instance using I2C communication
5#define SDA_PIN A4
6#define SCL_PIN A5
7Adafruit_PN532 nfc(SDA_PIN, SCL_PIN);
8
9void setup(void) {
10  Serial.begin(9600);
11  Serial.println("Initializing NFC Module...");
12
13  nfc.begin();
14
15  uint32_t versiondata = nfc.getFirmwareVersion();
16  if (!versiondata) {
17    Serial.println("Didn't find PN532 board");
18    while (1); // halt
19  }
20
21  // Configure board to read RFID tags
22  nfc.SAMConfig();
23  Serial.println("Waiting for an NFC tag...");
24}
25
26void loop(void) {
27  uint8_t success;
28  uint8_t uid[7];     // Buffer to store UID
29  uint8_t uidLength;  // Length of UID (4 or 7 bytes)
30
31  // Check for NFC tag presence
32  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
33
34  if (success) {
35    Serial.print("NFC Tag UID: ");
36    for (uint8_t i = 0; i < uidLength; i++) {
37      Serial.print(uid[i] < 0x10 ? " 0" : " ");
38      Serial.print(uid[i], HEX);
39    }
40    Serial.println();
41    delay(2000); // Small delay to avoid repeated reads
42  }
43}
44

Applications of NFC Modules

  • Secure access control systems
  • Contactless attendance tracking
  • Smart business cards
  • IoT automation triggers
  • Interactive installations
  • Cashless vending systems

Conclusion

Integrating an NFC module with Arduino opens up exciting possibilities in contactless technology. Whether you're building secure entry systems or experimenting with smart devices, this setup is an easy and practical entry into wireless communication.