PN532 NFC RFID module V3 (PN532) [S192]




https://www.youtube.com/watch?v=_kW7hPiGi2o


*GitHubhttps://github.com/rdiot/rdiot-s192.git



* Specs

PN532 is high-quality and reliable module that enables RFID and NFC communication with external devices: 

cards, smart phones etc. NFC itself supports two-way communication and data exchange, so possibilities are numerous. It connects with Croduino/Arduino through IIC or SPI communication.

 

IC: NXP PN532

Voltage: 5V

Communication: SPI or I2C

Max. device distance from reader: up to 7cm

It works with all most popular standards for RFID



* Contents

- Library : https://github.com/elechouse/PN532


- Connect

GND ----- GND

VCC ----- 5V

SDA ----- SDA

SCL ----- SCL


- Key Code

#include <Wire.h>

#include <PN532_I2C.h>

#include <PN532.h>

#include <NfcAdapter.h>

  

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: ");

    String hex_value = "";

    for (uint8_t i=0; i < uidLength; i++) 

    {

      Serial.print(" 0x");Serial.print(uid[i], HEX);       

      //Serial.print(" ");Serial.print(uid[i], HEX);       

      hex_value += (String)uid[i];

    }


    Serial.println(", value="+hex_value);


    if(hex_value == "16517722582") {

      Serial.println("This is Key Tag. ");

    }

    else if(hex_value == "230522426") {

      Serial.println("This is Card Tag. ");

    }

    else if(hex_value == "63156295") {

      Serial.println("This is Phone Tag. ");

    }

    else

      Serial.println("I don't know.");



    Serial.println("");

    // Wait 1 second before continuing

    delay(1000);

  }

  else

  {

    // PN532 probably timed out waiting for a card

    Serial.println("Waiting for a card...");

  }

}

'2) Sensor > RFID_NFC' 카테고리의 다른 글

NFC TAG Sticker ISO14443A (Ntag213) [S208]  (0) 2016.09.17
RFID-RC522 (MFRC-522) [S012]  (0) 2016.09.17
Posted by RDIoT
|