Electronics

RFID NFC Reader/Writer Module V3 PN532

AED 40.95

Low stock
1

Description

The PN532 is a straightforward NFC RFID Arduino-based module. Because of its functioning, this module differs from the other RFIC modules and devices. PN532 functionalities are used to define contemporary communication functions through an NFC chip. The single module includes three communication interfaces: UART, SPI, and I2C. Because of the official libraries in the Arduino IDE, the device most often communicates with the Arduino. The module is used to perform a variety of purposes such as data transmission, RFIC cards, and RFID readers. The gadget can only function at a close range of 5-7cm, however, because of its low power consumption and quick speed, most mobile firms are incorporating this module into their smartphones.

 

Specifications:

  • The PN532 enables the two modules to communicate any type of data at a defined distance.
  • The RFID module operates at a frequency of 13.56MHz and is allowed to use because to its short range.
  • The PN532 module may be used as an NTAG/RFID Card Tag and Reader.
  • The device can run on 3.3V for SPI and 5V for other types of connectivity.
  • The switch onboard aids in changing the communication protocol.
  • There are three types of protocols that may be used to interface with a single chip
  • The device includes an inbuilt antenna and is smaller in size, allowing it to be attached anywhere on the device without taking up too much room.
  • This is compatible with Android phones' NFC.

 

Applications:

  • Security keys like cars, doors, etc are using the RFID module in a wide range.
  • In mobiles, phone PN532 helps to exchange data.
  • In most of shopping malls, PN532 helps to identify the package.
  • In most Airports, PN532 helps to identify the luggage, bags, etc.

 

Pinout of the PN532 Module:

PN532 supports a variety of communication techniques. you can use the SPI or the I2C or the UART to communicate with the module, All of these pins are depicted on the pin diagram:
Pins Details
VCC VCC is to power up the whole device.
GND  GND pin helps to make the common ground with the power supply and the Arduino/Microcontroller.
UART Communication Pins
TXD UART communication requires two communication pins one for transmitting data and the second for receiving it. TXD helps to transmit the data.
RXD The RXD pin is the data receiving pin of the UART communication.
I2C Communication Pins
SDA I2C communication requires one pin for data transmission and receiving. Therefore, in the PN532 module SDA is a data pin for I2C communication.
SCL SCL is the clock pin of I2C communication. Data travel between devices according to the clock pulse.
IRQ IRQ pin is an interrupt pin, which helps to I2C communication to generate the interrupt to get the attention of the Arduino/Microcontroller.
RST RST is a reset pin, which helps to reset the device through an external signal. In PN532 this device is for I2C communication.
SPI Communication Pins
MOSI SPI communication requires 4-pins for data communication. Therefore, MOSI is a Master Out Slave In pin, it helps to transmit data from Arduino to PN532.
MISO MISO is a Master In Slave Out, it helps to transmit data from PN532 to Arduino.
SS SS is a slave select pin; it activates the SPI communication of the Slave (PN532).
SCK It’s a clock pin, helps in Transreceiving of data according to the clock pulse.

 

Connecting the PN532 Module with Arduino:

 

Arduino UNO

  • SPI
    • SS – D10
    • MOSI – D11
    • MISO – D12
    • SCK – D13
  • I2C
    • SCL – A5, D19
    • SDA – A4, D18
  • UART
    • RX – D0
    • TX – D1

The connectivity pins on the other Arduino board are different and may be seen on its official website. Everything will be done in accordance with the Arduino UNO. It also includes a toggle switch after connecting all communication pins with the PN532. The toggle switch pattern only allows one protocol to be active at a time.

SWITCH 1 SWITCH 2 PROTOCOL
0 0 UART
1 1 SPI
1 0 I2C

 

Programming PN532 with Arduino

This example will wait for any ISO14443A card or tag, and
depending on the size of the UID will attempt to read from it.

First, you will need to add the Adafruit_PN532 Library to you your Arduino IDE:

then, upload this code to your Board:

#include  "Wire.h"
#include "SPI.h"
#include "Adafruit_PN532.h"

// If using the breakout with SPI, define the pins for SPI communication.
#define PN532_SCK  (2)
#define PN532_MOSI (3)
#define PN532_SS   (4)
#define PN532_MISO (5)

// If using the breakout or shield with I2C, define just the pins connected
// to the IRQ and reset lines.  Use the values below (2, 3) for the shield!
#define PN532_IRQ   (2)
#define PN532_RESET (3)  // Not connected by default on the NFC Shield

// Uncomment just _one_ line below depending on how your breakout or shield
// is connected to the Arduino:

// Use this line for a breakout with a software SPI connection (recommended):
Adafruit_PN532 nfc(PN532_SCK, PN532_MISO, PN532_MOSI, PN532_SS);

// Use this line for a breakout with a hardware SPI connection.  Note that
// the PN532 SCK, MOSI, and MISO pins need to be connected to the Arduino's
// hardware SPI SCK, MOSI, and MISO pins.  On an Arduino Uno these are
// SCK = 13, MOSI = 11, MISO = 12.  The SS line can be any digital IO pin.
//Adafruit_PN532 nfc(PN532_SS);

// Or use this line for a breakout or shield with an I2C connection:
//Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);


void setup(void) {
  Serial.begin(115200);
  while (!Serial) delay(10); // for Leonardo/Micro/Zero

  Serial.println("Hello!");

  nfc.begin();

  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    Serial.print("Didn't find PN53x board");
    while (1); // halt
  }
  // Got ok data, print it out!
  Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX); 
  Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC); 
  Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
  
  // configure board to read RFID tags
  nfc.SAMConfig();
  
  Serial.println("Waiting for an ISO14443A Card ...");
}


void loop(void) {
  uint8_t success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
  uint8_t uidLength;                        // 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 uidLength will indicate
  // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
  
  if (success) {
    // Display some basic information about the card
    Serial.println("Found an ISO14443A card");
    Serial.print("  UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
    Serial.print("  UID Value: ");
    nfc.PrintHex(uid, uidLength);
    Serial.println("");
    
    if (uidLength == 4)
    {
      // We probably have a Mifare Classic card ... 
      Serial.println("Seems to be a Mifare Classic card (4 byte UID)");
	  
      // Now we need to try to authenticate it for read/write access
      // Try with the factory default KeyA: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
      Serial.println("Trying to authenticate block 4 with default KEYA value");
      uint8_t keya[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
	  
	  // Start with block 4 (the first block of sector 1) since sector 0
	  // contains the manufacturer data and it's probably better just
	  // to leave it alone unless you know what you're doing
      success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 4, 0, keya);
	  
      if (success)
      {
        Serial.println("Sector 1 (Blocks 4..7) has been authenticated");
        uint8_t data[16];
		
        // If you want to write something to block 4 to test with, uncomment
		// the following line and this text should be read back in a minute
        //memcpy(data, (const uint8_t[]){ 'a', 'd', 'a', 'f', 'r', 'u', 'i', 't', '.', 'c', 'o', 'm', 0, 0, 0, 0 }, sizeof data);
        // success = nfc.mifareclassic_WriteDataBlock (4, data);

        // Try to read the contents of block 4
        success = nfc.mifareclassic_ReadDataBlock(4, data);
		
        if (success)
        {
          // Data seems to have been read ... spit it out
          Serial.println("Reading Block 4:");
          nfc.PrintHexChar(data, 16);
          Serial.println("");
		  
          // Wait a bit before reading the card again
          delay(1000);
        }
        else
        {
          Serial.println("Ooops ... unable to read the requested block.  Try another key?");
        }
      }
      else
      {
        Serial.println("Ooops ... authentication failed: Try another key?");
      }
    }
    
    if (uidLength == 7)
    {
      // We probably have a Mifare Ultralight card ...
      Serial.println("Seems to be a Mifare Ultralight tag (7 byte UID)");
	  
      // Try to read the first general-purpose user page (#4)
      Serial.println("Reading page 4");
      uint8_t data[32];
      success = nfc.mifareultralight_ReadPage (4, data);
      if (success)
      {
        // Data seems to have been read ... spit it out
        nfc.PrintHexChar(data, 4);
        Serial.println("");
		
        // Wait a bit before reading the card again
        delay(1000);
      }
      else
      {
        Serial.println("Ooops ... unable to read the requested page!?");
      }
    }
  }
}


Place the card near the module after uploading the code. The card codes will be seen on the serial monitor.