#include <Wire.h>
#include <Adafruit_NFCShield_I2C.h>
#define IRQ (2)
#define RESET (3) // Not connected by default on the NFC Shield
//#define BlackTag 146150168253
//#define MetalTag 107238213236
//#define Tag 5999214236
//#define TagWired 9296A8FD
int Card1 = 0;
int Card2 = 0;
int Card3 = 0;
int Group = 0;
int GroupButton = 0;
String MetalTag= "107238213236";
String BlackTag="146150168253";
String Tag = "5999214236";
Adafruit_NFCShield_I2C nfc(IRQ, RESET);
String TagSwipe="";
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)
String str="";
// 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]);
String uidTemp=String(uid[i]);
str.concat(uidTemp);
}
Serial.println("");
Serial.println(str);
// Wait 1 second before continuing
delay(1000);
}
else
{
// PN532 probably timed out waiting for a card
Serial.println("Timed out waiting for a card");
}
{
int counter = 0;
if (str.equals(Tag) == true){
Serial.println("Tag"); Card1++;
}else if (str.equals(MetalTag) == true){
Serial.println("MetalTag"); Card2++;
}else if (str.equals(BlackTag) == true){
Serial.println("BlackTag"); Card3++;
}
GroupButton = 0;
if(GroupButton == 1){
if ( Card1>0) {Serial.print("Card1");}
if(Card2>0){Serial.print("Card2");}
if (Card3>0){Serial.print("Card3");}
}
else if (GroupButton == 0){
Serial.print("Group Button not pressed");
}
delay (1000);
}
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .