SSHS_CS_7반_2019_사감Box

A project that will bring better life for SSHS's guardians!

IntermediateShowcase (no instructions)71
SSHS_CS_7반_2019_사감Box

Things used in this project

Hardware components

Jumper wires (generic)
Jumper wires (generic)
×40
I2C 16x2 Arduino LCD Display Module
DFRobot I2C 16x2 Arduino LCD Display Module
×1
Arduino Mega 2560 & Genuino Mega 2560
Arduino Mega 2560 & Genuino Mega 2560
×1
Fingerprint Sensor
DFRobot Fingerprint Sensor
×1
HC-06 Bluetooth Module
×1
LED, RGB
LED, RGB
×1
TinyShield Real-Time Clock
TinyCircuits TinyShield Real-Time Clock
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Custom parts and enclosures

스마트폰 확인용 앱

Schematics

Schematic

Code

FINAL_JIMUN.ino

Arduino
The code for actual use
#include <Adafruit_Fingerprint.h>
#include <TimeLib.h>
#include <DS1302RTC.h>

#include <SoftwareSerial.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>



DS1302RTC RTC(4, 3, 2);

#define BT_RXD 40
#define BT_TXD 42
SoftwareSerial bluetooth(BT_RXD, BT_TXD);

LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display

SoftwareSerial mySerial(10, 11);
                                                                                                                
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

int redPin = 7;
int greenPin = 8;
int bluePin = 9;
int gPin = 6;
int bPin = 5;
int SHJHBH = 32;
int checklist[128]={0};
tmElements_t tm;

void setup()  
{
  
  lcd.init();                      // initialize the lcd 
  // Print a message to the LCD.
  lcd.backlight();
  Serial.begin(9600);
  
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(gPin, OUTPUT);
  pinMode(bPin, OUTPUT);
  digitalWrite(gPin, LOW);
  digitalWrite(bPin, HIGH);
  digitalWrite(SHJHBH, HIGH);

  RTC.haltRTC(0);
  RTC.writeEN(false);

  bluetooth.begin(9600);
  
    
  Serial.begin(9600);
  while (!Serial);  // For Yun/Leo/Micro/Zero/...
  delay(100);
  Serial.println("\n\nAdafruit finger detect test");

  // set the data rate for the sensor serial port
  finger.begin(57600);
  
  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1) { delay(1); }
  }

  finger.getTemplateCount();
  Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates");
  Serial.println("Waiting for valid finger...");

}

void loop()                     // run over and over again
{
    
    for(int j=0; checklist[j]; j++) {
    bluetooth.print(checklist[j]);
    bluetooth.println(" student checked in at");
    bluetooth.print(tm.Month);
    bluetooth.print("/");
    bluetooth.print(tm.Day);
    bluetooth.print(", ");
    bluetooth.print(tm.Hour);
    bluetooth.print(":");
    bluetooth.print(tm.Minute);
    bluetooth.print(":");
    bluetooth.print(tm.Second);
    }
  
  getFingerprintIDez();
  delay(50);            //don't ned to run this at full speed.
}

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");
      setColor(255, 0, 0); // red
      digitalWrite(redPin , HIGH);
      delay(1000);
      digitalWrite(redPin, LOW);
    return p;
  } else if (p == FINGERPRINT_NOTFOUND) {
    Serial.println("Did not find a match");
      setColor(255, 0, 0); // red
      digitalWrite(redPin , HIGH);
      delay(1000);
      digitalWrite(redPin, LOW);
    return p;
  } else {
    Serial.println("Unknown error");
      setColor(255, 0, 0); // red
      digitalWrite(redPin , HIGH);
      delay(1000);
      digitalWrite(redPin, LOW);
    return p;
  }   
  
  // found a match!
  Serial.print("Found ID #"); Serial.print(finger.fingerID); 
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
  
    lcd.setCursor(0, 0);
    lcd.print(finger.fingerID);
    lcd.print(" student ");
    lcd.setCursor(0, 1);
    if(RTC.read(tm)==0){
      //lcd.print(tmYearToCalendar(tm.Year));
      //lcd.print("/");
      lcd.print(tm.Month);
      lcd.print("/");
      lcd.print(tm.Day);
      lcd.print(", ");
      lcd.print(tm.Hour);
      lcd.print(":");
      lcd.print(tm.Minute);
      lcd.print(":");
      lcd.print(tm.Second);
    }
    else lcd.print("TRY AGAIN");

    for(int i=0; 1;) {
      if(!checklist[i]) {
        checklist[i] = finger.fingerID;
        break;
      }
      i++;
    }
      
      setColor(0, 255, 0); // green 
      delay(1000);
      digitalWrite(greenPin,LOW);
      digitalWrite(redPin,LOW);
      digitalWrite(bluePin,LOW);
      

  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!

  
    lcd.setCursor(0, 0);
    lcd.print(finger.fingerID);
    lcd.print(" student ");
    lcd.setCursor(0, 1);
    if(RTC.read(tm)==0){
      //lcd.print(tmYearToCalendar(tm.Year));
      //lcd.print("/");
      lcd.print(tm.Month);
      lcd.print("/");
      lcd.print(tm.Day);
      lcd.print(", ");
      lcd.print(tm.Hour);
      lcd.print(":");
      lcd.print(tm.Minute);
      lcd.print(":");
      lcd.print(tm.Second);
    }
    else lcd.print("TRY AGAIN");
    
    bluetooth.print(finger.fingerID);
    bluetooth.println(" student checked in at");
    
      bluetooth.print(tm.Month);
      bluetooth.print("/");
      bluetooth.print(tm.Day);
      bluetooth.print(", ");
      bluetooth.print(tm.Hour);
      bluetooth.print(":");
      bluetooth.print(tm.Minute);
      bluetooth.print(":");
      bluetooth.print(tm.Second);



    
      setColor(0, 255, 0); // green 
      delay(1000);
      digitalWrite(greenPin,LOW);
      digitalWrite(redPin,LOW);
      digitalWrite(bluePin,LOW);
  return finger.fingerID; 
}

void setColor(int red, int green, int blue)
{
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue);
}

FINAL_ENROLL.ino

Arduino
The code used to add fingerprints to our sensor
#include <Adafruit_Fingerprint.h>

// On Leonardo/Micro or others with hardware serial, use those! #0 is green wire, #1 is white
// uncomment this line:
// #define mySerial Serial1

// For UNO and others without hardware serial, we must use software serial...
// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino  (WHITE wire)
// comment these two lines if using hardware serial
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10,11);

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

uint8_t id;
int led1 = 5;
int led2 = 6;

void setup()  
{
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  Serial.begin(9600);
  while (!Serial);  // For Yun/Leo/Micro/Zero/...
  delay(100);
  Serial.println("\n\nAdafruit Fingerprint sensor enrollment");

  // set the data rate for the sensor serial port
  finger.begin(57600);
  
  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1) { delay(1); }
  }
}

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

void loop()                     // run over and over again
{
  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() );
}

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!");
      digitalWrite(led1, HIGH);
      delay(1000);
      digitalWrite(led1, LOW);
  } 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;
  }   
}

Credits

Kim Hojun

Kim Hojun

1 project • 0 followers
장광재

장광재

29 projects • 15 followers
박다솜

박다솜

14 projects • 2 followers
1716황보현

1716황보현

1 project • 0 followers
1707손현준

1707손현준

1 project • 0 followers
1706서유완

1706서유완

1 project • 0 followers

Comments

Add projectSign up / Login