งานที่ 15 ARDUINO FINGERPRINT SENSOR

Hardware





Software


  //////////////////////////////////////////////////////////////////
  //         Arduino Fingerprint Sensor Tutorial                  //
 //       Get the latest version of the code here:               //
// http://educ8s.tv/arduino-fingerprint-sensor-module-tutorial/ //
/////////////////////////////////////////////////////////////////


#include <SPI.h>
#include <Adafruit_GFX.h>
#include <TFT_ILI9163C.h>
#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>

// Color definitions
#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0  
#define WHITE   0xFFFF

#define __CS 10
#define __DC 9
static const uint8_t icon [] PROGMEM = {
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x3f,0xc0,0x0,0x0,0x0,
0x0,0x0,0x3,0xff,0xf8,0x0,0x0,0x0,
0x0,0x0,0x7,0xff,0xfe,0x0,0x0,0x0,
0x0,0x0,0x1f,0xc0,0x7f,0x80,0x0,0x0,
0x0,0x0,0x3e,0x0,0x7,0xc0,0x0,0x0,
0x0,0x0,0x7c,0x0,0x3,0xe0,0x0,0x0,
0x0,0x0,0xfd,0xff,0x81,0xf0,0x0,0x0,
0x0,0x0,0xff,0xff,0xe0,0xf0,0x0,0x0,
0x0,0x1,0xff,0xff,0xf8,0x78,0x0,0x0,
0x0,0x1,0xff,0x80,0x7c,0x38,0x0,0x0,
0x0,0x3,0xfc,0x0,0xe,0x3c,0x0,0x0,
0x0,0x3,0xf0,0x0,0x7,0x1c,0x0,0x0,
0x0,0x7,0xc0,0x7f,0x83,0x8e,0x0,0x0,
0x0,0x7,0x83,0xff,0xe0,0xe,0x0,0x0,
0x0,0x7,0xf,0xff,0xf8,0xf,0x0,0x0,
0x0,0x6,0x1f,0x80,0xfc,0x7,0x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8,0x0,0x0,
0x0,0x3,0xe1,0xff,0xff,0xe1,0x0,0x0,
0x0,0x1,0xe0,0x7f,0xff,0x83,0x0,0x0,
0x0,0x1,0xf8,0xf,0xfe,0x7,0x0,0x0,
0x0,0x0,0xfc,0x0,0x0,0xe,0x0,0x0,
0x0,0x0,0x3f,0x0,0x0,0x3c,0x0,0x0,
0x0,0x0,0x1f,0xe0,0x1,0xf8,0x0,0x0,
0x0,0x0,0x7,0xff,0xff,0xf0,0x0,0x0,
0x0,0x0,0x1,0xff,0xff,0xc0,0x0,0x0,
0x0,0x0,0x0,0x1f,0xfc,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0
};


TFT_ILI9163C display = TFT_ILI9163C(__CS,8, __DC);
SoftwareSerial mySerial(2, 3);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
int fingerprintID = 0;

void setup(void) {

  startFingerprintSensor();
  display.begin();
  displayLockScreen(); 
}

void loop() {

  fingerprintID = getFingerprintID();
  delay(50);
  if(fingerprintID == 1)
  {
    display.drawBitmap(30,35,icon,60,60,GREEN);
    delay(2000);
    displayUnlockedScreen();
    displayIoanna();
    delay(5000);
    display.fillScreen(BLACK);
    displayLockScreen();
  }

   if(fingerprintID == 2)
  {
    display.drawBitmap(30,35,icon,60,60,GREEN);
    delay(2000);
    displayUnlockedScreen();
    displayNick();
    delay(5000);
    display.fillScreen(BLACK);
    displayLockScreen();
  }
}


void displayUnlockedScreen()
{
   display.fillScreen(BLACK);
   display.drawRect(0,0,128,128,WHITE);
   
   display.setCursor(18,10);
   display.setTextColor(GREEN); 
   display.setTextSize(2);
   display.print("UNLOCKED");

   display.setCursor(20,50);
   display.setTextColor(WHITE); 
   display.setTextSize(2);
   display.print("WELCOME");
}
void displayNick()
{
  display.setCursor(35,75);
  display.setTextColor(WHITE); 
  display.setTextSize(2);
  display.print("NICK!");
}

void displayIoanna()
{
  display.setCursor(25,75);
  display.setTextColor(WHITE); 
  display.setTextSize(2);
  display.print("IOANNA!");
}

void displayLockScreen()
{
  display.drawRect(0,0,128,128,WHITE);
  display.setCursor(30,10);
  display.setTextColor(RED); 
  display.setTextSize(2);
  display.print("LOCKED");

  display.setCursor(10,100);
  display.setTextColor(WHITE); 
  display.setTextSize(1);
  display.print("Waiting for valid \n    fingerprint.");

  display.drawBitmap(30,35,icon,60,60,WHITE);
}
void startFingerprintSensor()
{
  Serial.begin(9600);
  finger.begin(57600);
  
  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor");
  }
  Serial.println("Waiting for valid finger...");
}

int getFingerprintID() {
  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; 
}

ความคิดเห็น

โพสต์ยอดนิยมจากบล็อกนี้

งาน FLOWCHART

งาน arduino 5 photo transistor

งาน arduino 7 Voltage Sensor