The Adafruit PN532 NFC RFID Controller Shield is a highly integrated board designed for near-field communication (NFC) and radio-frequency identification (RFID) applications. It is based on the popular NXP PN532 chip and can be used to read and write NFC and RFID tags. This shield supports several protocols, including ISO/IEC 14443 A and B, FeliCa, and ISO/IEC 15693, making it suitable for a wide range of applications such as contactless payment systems, access control, and personal identification.
Pin Number | Name | Description |
---|---|---|
1 | SDA | Serial Data for I2C communication |
2 | SCL | Serial Clock for I2C communication |
3 | MOSI | Master Out Slave In for SPI communication |
4 | MISO | Master In Slave Out for SPI communication |
5 | SCK | Serial Clock for SPI communication |
6 | IRQ | Interrupt Request, active LOW |
7 | RSTO | Reset Output from PN532 to external MCU, active LOW |
8 | GND | Ground |
9 | 5V | 5V Power Supply |
10 | 3V | 3.3V Power Supply |
#include <Wire.h>
#include <Adafruit_PN532.h>
// If using the I2C interface, use the following line:
Adafruit_PN532 nfc(PN532_SDA, PN532_SCL);
void setup(void) {
Serial.begin(115200);
Serial.println("Hello! Scan a NFC tag!");
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if (!versiondata) {
Serial.print("Didn't find PN53x board");
while (1); // halt
}
// Configure board to read RFID tags
nfc.SAMConfig();
}
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 card (Mifare, etc.). When one is found, 'uid' will be populated
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: ");
for (uint8_t i=0; i < uidLength; i++) {
Serial.print(" 0x");Serial.print(uid[i], HEX);
}
Serial.println("");
// Wait 1 second before continuing
delay(1000);
}
}
Q: Can the shield read all types of RFID tags? A: The shield can read tags that operate at 13.56MHz and support ISO/IEC 14443 A and B, FeliCa, and ISO/IEC 15693.
Q: How can I increase the reading distance? A: The reading distance is primarily determined by the antenna design and cannot be significantly increased. Ensure optimal positioning and avoid interference for the best results.
Q: Is the shield compatible with other microcontrollers besides Arduino UNO? A: Yes, the shield can be used with other microcontrollers that support I2C, SPI, or HSU interfaces, provided that the voltage levels are compatible.