指紋辨識門鎖 Fingerprint Identification Lock

Description

Description

作者:國立高雄大學 張廷瑋 、徐義鴻

指導教授:曹永忠博⼠

Introduction

  • Some people feel inconvenient to open the door using the home key when home.
  • So, we want to design a system to automatically open the door.

Materials needed

  • Nodemcu
  • Raspberry 3B
  • Fingerprint scanner  –  GT-511C3
  • I2C LCD Screen
  • Relay
  • Magnetic lock
  • Button
  • Breadboard Power Supply

How does it work?

When Fingerprint Reader finds the person who had signed up his finger data, then open the door and sent data to lamp server.

Lamp server saves data into the Mysql database and shows it on the web.

Code

#include “FPS_GT511C3.h”
#include “SoftwareSerial.h”
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <ArduinoJson.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>

LiquidCrystal_I2C lcd(0x3F,16,2); //設定LCD位置 0x27 or 0x3F,設定LCD大小為16*2

int relayInput = 2; // the input to the relay pin

const char* ssid = “Cawaii”; // “iNUK_DEV”
const char* password = “0989335521”;
const char* mqttServer = “140.127.220.208”; // MQTT伺服器位址
const char* mqttUserName = “cawaii”; // 使用者名稱,隨意設定。
const char* mqttPwd = “你的MQTT API Key”; // MQTT密碼
const char* clientID = “fingerprintreader01”; // 用戶端ID,隨意設定。
const char* topic = “test/1”;

unsigned long prevMillis = 0; // 暫存經過時間(毫秒)
const long interval = 20000; // 上傳資料的間隔時間,20秒。
String msgStr = “”; // 暫存MQTT訊息字串

WiFiClient espClient;
PubSubClient client(espClient);

FPS_GT511C3 fps(D5, D6);

void setup_wifi() {
delay(10);
Serial.print(“Connecting to “);
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(“.”);
}

Serial.println(“”);
Serial.println(“WiFi connected”);
lcd.print(“WiFi connected!”);
}

void reconnect() {
while (!client.connected()) {
if (client.connect(clientID, mqttUserName, mqttPwd)) {
Serial.println(“MQTT connected”);
lcd.print(“MQTT connected!”);
} else {
Serial.print(“failed, rc=”);
Serial.print(client.state());
Serial.println(” try again in 5 seconds”);
delay(5000); // 等5秒之後再重試
}
}
}

void setup(){
Serial.begin(9600);
delay(100);
ESP.wdtDisable();
setup_wifi();
client.setServer(mqttServer, 1883);
reconnect();
pinMode(relayInput, OUTPUT); // initialize pin as OUTPUT
digitalWrite(relayInput, LOW); // turn relay off

lcd.begin(); //初始化LCD
lcd.backlight(); //開啟背光
lcd.print(“GT511C3 Start”); //Intro Message line 1
delay(2000);
lcd.clear();

fps.Open();
fps.SetLED(true);
pinMode(D3,INPUT_PULLUP); //Connect to internal pull up resistor as input pin
}

void loop() {
if (!client.connected()) {
reconnect();
}
if (client.connected()){
if (digitalRead(D3)==0)//If button pressed
{
Enroll(); //Enroll a fingerprint
}

// Identify fingerprint test
if (fps.IsPressFinger()) {
fps.CaptureFinger(false);
int id = fps.Identify1_N();
lcd.clear();
lcd.print(“Welcome:”);
if (id==200) {
lcd.print(“Unkown “); //If not recognised
Serial.println(“Finger not found”);
delay(1000);
}
if (id < 200) {
digitalWrite(relayInput, HIGH); // turn relay on
Serial.print(“Verified ID:”);
Serial.println(id);
lcd.print(id);

//連上mqttServer 發出開門訊息
client.loop();
StaticJsonBuffer<200> jsonBuffer;
JsonObject& jsonData = jsonBuffer.createObject();
String msg ;
jsonData[“Date”] = “”;
jsonData[“Sensor_ID”] = 1 ;
jsonData[“ID”] = id ;
jsonData[“Status”] = 1 ;
jsonData.printTo(msg);
char message[90];
msg.toCharArray(message,90);

Serial.print(“Publish message: “);
Serial.println(message);
//publish sensor data to MQTT broker
client.publish(topic, message); // 發布MQTT主題與訊息

delay(2000);
digitalWrite(relayInput, LOW);
}
}
else
{
Serial.println(“Please press finger”);
lcd.clear();
lcd.print(“Hi!…..”); //Display hi when ready to scan
}
}
}
void Enroll() //Enrol function from library exmaple program
{
int enrollid = 0;
bool usedid = true;
while (usedid == true)
{
usedid = fps.CheckEnrolled(enrollid);
if (usedid==true) enrollid++;
}
fps.EnrollStart(enrollid);

// enroll
lcd.clear();
lcd.print(“Enroll #”);
lcd.print(enrollid);
while(fps.IsPressFinger() == false) delay(100);
bool bret = fps.CaptureFinger(true);
int iret = 0;
if (bret != false)
{
lcd.clear();
lcd.print(“Remove finger”);
fps.Enroll1();
while(fps.IsPressFinger() == true) delay(100);
lcd.clear(); lcd.print(“Press again”);
while(fps.IsPressFinger() == false) delay(100);
bret = fps.CaptureFinger(true);
if (bret != false)
{
lcd.clear(); lcd.print(“Remove finger”);
fps.Enroll2();
while(fps.IsPressFinger() == true) delay(100);
lcd.clear(); lcd.print(“Press yet again”);
while(fps.IsPressFinger() == false) delay(100);
bret = fps.CaptureFinger(true);
if (bret != false)
{
lcd.clear(); lcd.print(“Remove finger”);
iret = fps.Enroll3();
if (iret == 0)
{
lcd.clear(); lcd.print(“Enrolling Success”);
}
else
{
lcd.clear();
lcd.print(“Enroll Failed:”);
lcd.print(iret);
}
}
else lcd.print(“Failed 1”);
delay(500);
}
else lcd.print(“Failed 2”);
delay(500);
}
else lcd.print(“Failed 3”);
delay(500);
}

Latest posts by YI-Hung Hsu (see all)

    Contact

    Contact
    • Category
      Raspberry Pi, 開發板
    • Tags
      Arduino

    Project簡述

    Project簡述
    • 簡述
      希望透過自動化的指紋辨識門鎖,讓大家可以更便利!
    • 作者
      張廷瑋 、徐義鴻

    您的姓名 〈需填寫〉

    您的電子郵件信箱 〈需填寫〉

    主旨

    您的信件內容