PN532 NFC RFID V3
รายละเอียด
PN532 NFC RFID Module เป็นโมดูลสื่อสารไร้สายระยะสั้นระยะประมาณ 4 ซม. ที่ใช้ได้ดีกับโครงสร้างพื้นฐานแบบไร้สัมผัส ช่วยสนับสนุนรองรับการสื่อสารระหว่างเครื่องมืออิเล็กทรอนิกส์ในระยะใกล้ๆ รองรับการใช้งานแบบ II2, SPI และ HSU (High Speed UART) ใช้ไฟเลี้ยง 5V
ประกอบด้วย
Items Quantity
PN532 NFC RFID Module 1
2.54 mm spacing 4pin Cable 1
Mifare One S50 White Card 1
Mifare One S50 Key Card 1
12P bended male pins
การต่อวงจร
Vcc - > 3.3 / 5 V
Gnd -> Gnd
SCL -> A5
SDA -> A4
โค้ดตัวอย่างการใช้งาน
#include
#include <PN532_I2C.h>
#include
PN532_I2C pn532i2c(Wire);
PN532 nfc(pn532i2c);
void setup(void)
{
Serial.begin(115200);
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);
// Set the max number of retry attempts to read from a card
// This prevents us from waiting forever for a card, which is
// the default behaviour of the PN532.
nfc.setPassiveActivationRetries(0xFF);
// configure board to read RFID tags
nfc.SAMConfig();
Serial.println("Waiting for an ISO14443A card");
}
void loop(void)
{
boolean 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[0], &uidLength);
if (success)
{
Serial.println("Found a 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);
}
else
{
// PN532 probably timed out waiting for a card
Serial.println("Timed out waiting for a card");
}
}
หน้าจอแสดงผลขณะยังไม่แตะ PN532 NFC RFID
หน้าจอแสดงผลขณะแตะ PN532 NFC RFID
อ้างอิง
https://www.arduinoall.com/product/146/rfid-nfc-module-kit-pn532-พร้อมแท็ก-2-ชิ้น-card-พวงกุญแจ



ไม่มีความคิดเห็น:
แสดงความคิดเห็น