Cara Mudah Program FingerPrint Dengan Arduino (ENROLL, FINGEPRINT, DELETE)

Karena banyak permintaan dari agan-agan penghuni Grup WhatsApp Kelas Robot, akhirnya saya luangkan waktu untuk membuat Tutorial Arduino dengan FingerPrint Sensor.

Yang perlu kamu siapkan adalah:

  1. 1x Arduino Uno BELI
  2. 1x FingerPrint Sensor BELI

Kemudian rangkai seperti pada gambar dibawah ini:

Sebelum masuk pemrograman, Kamu WAJIB untuk mendownload Library FingerPrint Sensor, lalu add ke Arduino IDE kamu.

Download Adafruit Fingerprint Sensor Library Master

Bagi yang belum tau cara ADD Library ke Arduino IDE, silahkan ikuti Tutorial dibawah ini:

Bagaimana Cara Memasukan Library Ke Aplikasi Arduino IDE?

***

#1 ENROLL

Selanjutnya adalah kita akan Upload Program Enroll, yaitu Program untuk mendaptarkan Jari kamu ke Fingerprint Sensor. Silahkan gunakan program dibawah ini:

#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
uint8_t id;

void setup(){
  Serial.begin(9600);
  finger.begin(57600);

  if (finger.verifyPassword()) {
    Serial.println("FingerPrint Sensor Ditemukan!");
  } else {
    Serial.println("FingerPrint Sensor Tidak Ditemukan! :(");
    while (1) { delay(1); }
  }
  
}



void loop(){
  ENROLL();
}




//---------------------------------------ENROLL--------------------------------------------------------------//
void ENROLL(){
  Serial.println("Ready to enroll a fingerprint!");
  Serial.println("Please type in the ID # (from 1 to 127) you want to save this finger as...");
  id = readnumber();
  if (id == 0) {// ID #0 not allowed, try again!
     return;
  }
  Serial.print("Enrolling ID #");
  Serial.println(id);
  
  while (!  getFingerprintEnroll() );
}

//------------------------------------PROSES ENROLL----------------------------------------------------------//

uint8_t readnumber(void) {
  uint8_t num = 0;
  
  while (num == 0) {
    while (! Serial.available());
    num = Serial.parseInt();
  }
  return num;
}

//----RETURN NUM-------------------//

uint8_t getFingerprintEnroll() {
  int p = -1;
  Serial.print("Waiting for valid finger to enroll as #"); Serial.println(id);
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println(".");
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      break;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      break;
    default:
      Serial.println("Unknown error");
      break;
    }
  }

  // OK success!

  p = finger.image2Tz(1);
  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;
  }
  
  Serial.println("Remove finger");
  delay(2000);
  p = 0;
  while (p != FINGERPRINT_NOFINGER) {
    p = finger.getImage();
  }
  Serial.print("ID "); Serial.println(id);
  p = -1;
  Serial.println("Place same finger again");
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.print(".");
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      break;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      break;
    default:
      Serial.println("Unknown error");
      break;
    }
  }

  // OK success!

  p = finger.image2Tz(2);
  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!
  Serial.print("Creating model for #");  Serial.println(id);
  
  p = finger.createModel();
  if (p == FINGERPRINT_OK) {
    Serial.println("Prints matched!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_ENROLLMISMATCH) {
    Serial.println("Fingerprints did not match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }   
  
  Serial.print("ID "); Serial.println(id);
  p = finger.storeModel(id);
  if (p == FINGERPRINT_OK) {
    Serial.println("Stored!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_BADLOCATION) {
    Serial.println("Could not store in that location");
    return p;
  } else if (p == FINGERPRINT_FLASHERR) {
    Serial.println("Error writing to flash");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }   
}

//---------------------------------------ENROLL END--------------------------------//

Jika sudah DONE UPLOADING, silahkan buka Serial Monitor untuk mendaptarkan jari kamu.

Silahkan masukan angka dari 1-127, nomer untuk menyimpan jari kamu lalu klik Send atau tekan Enter.
Lalu letakan Jari kamu ke Fingerprint sensor.

Kemudian lepas Jari Kamu, lalu letakan lagi untuk Konfirmasi.

Jika sudah ada keterangan Stored, berarti jari kamu berhasil di daftarkan.

***

#2 FINGERPRINT

Setelah selesai melakukan Enroll, selanjutnya kamu bisa coba program Fingerprint, yaitu program untuk cek jari kamu terdaftar atau tidak. Silahkan gunakan program dibawah ini:

#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup(){
  Serial.begin(9600);
  finger.begin(57600);

  if (finger.verifyPassword()) {
    Serial.println("FingerPrint Sensor Ditemukan!");
  } else {
    Serial.println("FingerPrint Sensor Tidak Ditemukan! :(");
    while (1) { delay(1); }
  }
  
}

void loop(){
  FINGERPRINT();
}

//----------------------------------------------------FINGERPRINt----------------------------------------------//
void FINGERPRINT(){
  getFingerprintIDez();
  delay(50);
}

//----------------------------------------------------PROSES FINGERPRINT--------------------------------------//

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

  return finger.fingerID;
}

// 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; 
}

//--------------------------------END FINGERPRINT----------------------------------------------//

jika sudah DONE UPLOADING, silahkan buka Serial Monitor, lalu letakan jari kamu di sensor.

Lalu jika muncul Found ID, berarti jari kamu sudah terdaftar di Fingerprint Sensor.

***

#3 DELETE

Program terakhir adalah program Delete, ini fungsinya untuk menghapus data Jari yang sudah terdaftar di Fingerprint Sensor. Silahkan gunakan program dibawah ini:

 

#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup(){
  Serial.begin(9600);
  finger.begin(57600);

  if (finger.verifyPassword()) {
    Serial.println("FingerPrint Sensor Ditemukan!");
  } else {
    Serial.println("FingerPrint Sensor Tidak Ditemukan! :(");
    while (1) { delay(1); }
  }
  
}

void loop(){
  DELETE();
}


//------------------------------------------DELETE-----------------------------------//
void DELETE(){
  Serial.println("Please type in the ID # (from 1 to 127) you want to delete...");
  uint8_t id = readnumber();
  if (id == 0) {// ID #0 not allowed, try again!
     return;
  }
  Serial.print("Deleting ID #");
  Serial.println(id);
  deleteFingerprint(id);
}
//------------------------------------------PROSES DELETE---------------------------//

uint8_t readnumber(void) {
  uint8_t num = 0;
  
  while (num == 0) {
    while (! Serial.available());
    num = Serial.parseInt();
  }
  return num;
}

//----RETURN NUM-------------------//


uint8_t deleteFingerprint(uint8_t id) {
  uint8_t p = -1;
  
  p = finger.deleteModel(id);

  if (p == FINGERPRINT_OK) {
    Serial.println("Deleted!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_BADLOCATION) {
    Serial.println("Could not delete in that location");
    return p;
  } else if (p == FINGERPRINT_FLASHERR) {
    Serial.println("Error writing to flash");
    return p;
  } else {
    Serial.print("Unknown error: 0x"); Serial.println(p, HEX);
    return p;
  }   
}

jika sudah DONE UPLOADING, silahkan buka Serial Monitor.

Lalu masukan no ID yang ingin kamu hapus, lalu klik Send atau Tekan Enter.

Jika sudah ada keterangan Deleted!, artinya data jari yang terdaptar di Fingerprint Sensor sudah terhapus. Silahkan kamu coba letakan lagi jarinya di sensor untuk mengetes.

***

Oke sekian Tutorial kali ini, jika kamu berhasil membuatnya silahkan kamu Share di Kolom komentar ya. Thanks

You May Also Like

About the Author: Ajang Rahmat

5 Comments

Leave a Reply to Anonymous Cancel reply

Your email address will not be published. Required fields are marked *