//Get library from https://github.com/ljos/MFRC522 //Sketch: [email protected]
int getFingerprintIDez();
// pin #2 is IN from sensor (GREEN wire) // pin #3 is OUT from arduino (WHITE wire) SoftwareSerial mySerial(2, 3);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
/* Pins SPI UNO Mega2560 Leonardo 1 (NSS) SAD (SS) 10 53 10 2 SCK 13 52 SCK1 3 MOSI 11 51 MOSI1 4 MISO 12 50 MISO1 5 IRQ * * * 6 GND GND GND GND 7 RST 5 ? Reset 8 +3.3V (VCC) 3V3 3V3 3.3V * Not needed 1 on ICPS header */
MFRC522 nfc(SAD, RST);
void setup() {
pinMode(ledPinOpen , OUTPUT);
pinMode(ledPinClosed, OUTPUT);
SPI.begin();
Serial.begin(115200);
Serial.println("Looking for MFRC522.");
nfc.begin();
byte version = nfc.getFirmwareVersion();
if (! version) {
Serial.print("Didn't find MFRC522 board.");
while(1); //halt
}
Serial.print("Found chip MFRC522 "); Serial.print("Firmware ver. 0x"); Serial.print(version, HEX); Serial.println(".");
if (finger.verifyPassword()) { Serial.println("Found fingerprint sensor!"); } else { Serial.println("Did not find fingerprint sensor :("); while (1); } Serial.println("Waiting for valid finger..."); }
byte Authorized[AUTHORIZED_COUNT][6] = {
{0x33, 0x3E, 0xFA, 0x35, 0xFF, 0xFF, }
/*,{0x10, 0x14, 0x39, 0x2E, 0xFF, 0xFF, }*/ /*f. example how to add more authorized cards*/
};
void printSerial(byte *serial); boolean isSame(byte *key, byte *serial); boolean isAuthorized(byte *serial);
void loop() { byte status; byte data[MAX_LEN]; byte serial[5]; boolean Opening = false; digitalWrite(ledPinOpen, Opening); digitalWrite(ledPinClosed, !Opening); status = nfc.requestTag(MF1_REQIDL, data);
if (status == MI_OK) { status = nfc.antiCollision(data); memcpy(serial, data, 5);
if(isAuthorized(serial))
{
Serial.println("Authenticated");
Opening = true;
}
else
{
printSerial(serial);
Serial.println("is NOT authenticated");
Opening = false;
}
nfc.haltTag();
digitalWrite(ledPinOpen, Opening);
digitalWrite(ledPinClosed, !Opening);
delay(2000);
}//if (status == MI_OK)
delay(500);
getFingerprintIDez(); delay(50); //don't ned to run this at full speed.
}//void loop()
boolean isSame(byte *key, byte *serial) { for (int i = 0; i < 4; i++) { if (key[i] != serial[i]) { return false; } }
return true;
}
boolean isAuthorized(byte *serial) { for(int i = 0; i<AUTHORIZED_COUNT; i++) { if(isSame(serial, Authorized[i])) return true; } return false; }
void printSerial(byte *serial) { Serial.print("Serial:"); for (int i = 0; i < 4; i++) { Serial.print(serial[i], HEX); Serial.print(" "); } }
uint8_t getFingerprintID() { uint8_t p = finger.getImage(); switch (p) { case FINGERPRINT_OK: Serial.println("Image taken"); break; case FINGERPRINT_NOFINGER: Serial.println("No finger detected"); return p; case FINGERPRINT_PACKETRECIEVEERR: Serial.println("Communication error"); return p; case FINGERPRINT_IMAGEFAIL: Serial.println("Imaging error"); return p; default: Serial.println("Unknown error"); return p; }
// OK success!
p = finger.image2Tz(); switch (p) { case FINGERPRINT_OK: Serial.println("Image converted"); break; case FINGERPRINT_IMAGEMESS: Serial.println("Image too messy"); return p; case FINGERPRINT_PACKETRECIEVEERR: Serial.println("Communication error"); return p; case FINGERPRINT_FEATUREFAIL: Serial.println("Could not find fingerprint features"); return p; case FINGERPRINT_INVALIDIMAGE: Serial.println("Could not find fingerprint features"); return p; default: Serial.println("Unknown error"); return p; }
// OK converted! p = finger.fingerFastSearch(); if (p == FINGERPRINT_OK) { Serial.println("Found a print match!"); } else if (p == FINGERPRINT_PACKETRECIEVEERR) { Serial.println("Communication error"); return p; } else if (p == FINGERPRINT_NOTFOUND) { Serial.println("Did not find a match"); return p; } else { Serial.println("Unknown error"); return p; }
// found a match! Serial.print("Found ID #"); Serial.print(finger.fingerID); Serial.print(" with confidence of "); Serial.println(finger.confidence); }
// returns -1 if failed, otherwise returns ID # int getFingerprintIDez() { uint8_t p = finger.getImage(); if (p != FINGERPRINT_OK) return -1;
p = finger.image2Tz(); if (p != FINGERPRINT_OK) return -1;
p = finger.fingerFastSearch(); if (p != FINGERPRINT_OK) return -1;
// found a match! Serial.print("Found ID #"); Serial.print(finger.fingerID); Serial.print(" with confidence of "); Serial.println(finger.confidence); return finger.fingerID; }