就是闲的没事,看见某超级大佬也弄了一个,觉得挺好,然后自己也实践实践。
总共,大概花了一周时间吧。
自己
查考博客:
https://blog.csdn.net/woshi_ziyu/article/details/88200664
https://blog.csdn.net/m0_54003252/article/details/114542500我也是参考这篇博客采购的
自己用的零件: uno板子,线公对公、母对母尽量多,充电宝(寝室停电使用要一个9V供电的(不过5V好像也够)),面包板,as608,SG90S舵机,一根强度比较高的线(通过舵机拉门用),LCD1602显示屏焊好的。
成本大概150左右,不要充电宝就110。
首先需要知道怎么接线,我花2-3天看的这个b站视频,第一部分看一大半就知道怎么接了:链接
然后东西到了开始接线。
指纹模
Vi 3.3V
Tx 2管脚
Rx 3管脚
GND GND
SG90舵机
VCC(红色线) 5V
I/O(橙色线) 8管脚
GND(黑色线) GND
舵机注意方向!!当时门把手没拉动我还以为力不够!结果是初始位置搞错了,导致先回到初始位置才开始旋转。
这个是lcd的使用方法:
https://blog.csdn.net/acktomas/article/details/88136405
lcd参考上面那个博客接线!
注意lcd 先找地址!具体可以上面的博客
需要安装的库
指纹库 fingerprint github下载地址:链接
LCD库 LiquidCrystal_I2C github下载地址:链接
下载后2个文件后,将文件放进arduino的libraries(我用的苹果m1,windons其他博客应该会写。)进入方法找到arduino图标右键->contents->Java->libraries
指纹库 fingerprint 的文件还要放进arduino图标右键->contents->Java->examples里。
然后打开ardiuno。
接下来参考视频:https://www.bilibili.com/video/BV1tb411a7by?t=45参考他怎么烧录和操作的。
下面代码:大部分我自己改成中文了,这样看的时候方便。
烧录指纹代码:
/***************************************************
This is an example sketch for our optical Fingerprint sensor
Designed specifically to work with the Adafruit BMP085 Breakout
----> http://www.adafruit.com/products/751
These displays use TTL Serial to communicate, 2 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
#include
#if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__)
// 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)
// Set up the serial port to use softwareserial..
SoftwareSerial mySerial(2, 3);
#else
// On Leonardo/M0/etc, others with hardware serial, use hardware serial!
// #0 is green wire, #1 is white
#define mySerial Serial1
#endif
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
uint8_t id;
void setup()
{
Serial.begin(9600);
while (!Serial); // For Yun/Leo/Micro/Zero/...
delay(100);
Serial.println("\n\n指纹传感器登记");
// set the data rate for the sensor serial port
finger.begin(57600);
if (finger.verifyPassword()) {
Serial.println("找到指纹传感器");
} else {
Serial.println("没有找到指纹传感器:(");
while (1) { delay(1); }
}
Serial.println(F("阅读传感器参数"));
finger.getParameters();
Serial.print(F("状态: 0x")); Serial.println(finger.status_reg, HEX);
Serial.print(F("Sys ID: 0x")); Serial.println(finger.system_id, HEX);
Serial.print(F("Capacity: ")); Serial.println(finger.capacity);
Serial.print(F("安全等级: ")); Serial.println(finger.security_level);
Serial.print(F("设备地址: ")); Serial.println(finger.device_addr, HEX);
Serial.print(F("Packet len: ")); Serial.println(finger.packet_len);
Serial.print(F("波特率: ")); Serial.println(finger.baud_rate);
}
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("准备注册指纹!");
Serial.println("请输入ID号(从1到127),你想保存这个手指为…");
id = readnumber();
if (id == 0) {// ID #0 not allowed, try again!
return;
}
Serial.print("注册 ID #");
Serial.println(id);
while (! getFingerprintEnroll() );
}
uint8_t getFingerprintEnroll() {
int p = -1;
Serial.print("等待有效的手指注册为#"); Serial.println(id);
while (p != FINGERPRINT_OK) {
p = finger.getImage();
switch (p) {
case FINGERPRINT_OK:
Serial.println("拍摄");
break;
case FINGERPRINT_NOFINGER:
Serial.println(".");
break;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("通信错误");
break;
case FINGERPRINT_IMAGEFAIL:
Serial.println("成像错误");
break;
default:
Serial.println("未知错误");
break;
}
}
// OK success!
p = finger.image2Tz(1);
switch (p) {
case FINGERPRINT_OK:
Serial.println("图像转换");
break;
case FINGERPRINT_IMAGEMESS:
Serial.println("图像太混乱");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("通信错误");
return p;
case FINGERPRINT_FEATUREFAIL:
Serial.println("找不到指纹特征");
return p;
case FINGERPRINT_INVALIDIMAGE:
Serial.println("找不到指纹特征");
return p;
default:
Serial.println("未知错误");
return p;
}
Serial.println("请拿开手指");
delay(2000);
p = 0;
while (p != FINGERPRINT_NOFINGER) {
p = finger.getImage();
}
Serial.print("ID "); Serial.println(id);
p = -1;
Serial.println("再次放同一个手指");
while (p != FINGERPRINT_OK) {
p = finger.getImage();
switch (p) {
case FINGERPRINT_OK:
Serial.println("拍摄");
break;
case FINGERPRINT_NOFINGER:
Serial.print(".");
break;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("通信错误");
break;
case FINGERPRINT_IMAGEFAIL:
Serial.println("成像错误");
break;
default:
Serial.println("未知错误");
break;
}
}
// OK success!
p = finger.image2Tz(2);
switch (p) {
case FINGERPRINT_OK:
Serial.println("图像转换");
break;
case FINGERPRINT_IMAGEMESS:
Serial.println("图像太混乱");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("通信错误");
return p;
case FINGERPRINT_FEATUREFAIL:
Serial.println("找不到指纹特征");
return p;
case FINGERPRINT_INVALIDIMAGE:
Serial.println("找不到指纹特征");
return p;
default:
Serial.println("未知错误");
return p;
}
// OK converted!
Serial.print("创建模型为#"); Serial.println(id);
p = finger.createModel();
if (p == FINGERPRINT_OK) {
Serial.println("打印匹配!");
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
Serial.println("通信错误");
return p;
} else if (p == FINGERPRINT_ENROLLMISMATCH) {
Serial.println("指纹不匹配");
return p;
} else {
Serial.println("未知错误");
return p;
}
Serial.print("ID "); Serial.println(id);
p = finger.storeModel(id);
if (p == FINGERPRINT_OK) {
Serial.println("存储!");
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
Serial.println("通信错误");
return p;
} else if (p == FINGERPRINT_BADLOCATION) {
Serial.println("不能存储在那个位置");
return p;
} else if (p == FINGERPRINT_FLASHERR) {
Serial.println("写入闪存错误");
return p;
} else {
Serial.println("未知错误");
return p;
}
return true;
}
指纹锁代码:
/***************************************************
This is an example sketch for our optical Fingerprint sensor
Designed specifically to work with the Adafruit BMP085 Breakout
----> http://www.adafruit.com/products/751
These displays use TTL Serial to communicate, 2 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
#include
#include
#include
LiquidCrystal_I2C lcd(0x27, 16, 2);
int servopin = 8;
int buzzer = 5;
void servopulse(int angle)//定义一个脉冲函数
{
int pulsewidth = (angle * 11) + 500; //将角度转化为500-2480的脉宽值
digitalWrite(servopin, HIGH); //将舵机接口电平至高
delayMicroseconds(pulsewidth); //延时脉宽值的微秒数
digitalWrite(servopin, LOW); //将舵机接口电平至低
delayMicroseconds(20000 - pulsewidth);
}
#if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__)
// 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)
// Set up the serial port to use softwareserial..
SoftwareSerial mySerial(2, 3);
#else
// On Leonardo/M0/etc, others with hardware serial, use hardware serial!
// #0 is green wire, #1 is white
#define mySerial Serial1
#endif
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
void setup()
{
Serial.begin(9600);
while (!Serial); // For Yun/Leo/Micro/Zero/...
delay(100);
Serial.println("\n\n手指检测测试");
// set the data rate for the sensor serial port
finger.begin(57600);
delay(5);
lcd.init(); // 初始化LCD
lcd.backlight(); //设置LCD背景等亮
if (finger.verifyPassword()) {
Serial.println("发现指纹传感器 憨批!");
lcd.setCursor(0,0);
lcd.print("Found fingerprint");
delay(1000);
} else {
Serial.println("No Found fingerprint sensor");
lcd.setCursor(0,0);
lcd.print("no find!");
lcd.setCursor(0,1);
lcd.print("Check Connections");
delay(1000);
while (1) {
delay(1);
}
}
lcd.clear();
Serial.println(F("阅读传感器参数"));
finger.getParameters();
Serial.print(F("状态: 0x")); Serial.println(finger.status_reg, HEX);
Serial.print(F("Sys ID: 0x")); Serial.println(finger.system_id, HEX);
Serial.print(F("Capacity: ")); Serial.println(finger.capacity);
Serial.print(F("安全等级: ")); Serial.println(finger.security_level);
Serial.print(F("设备地址: ")); Serial.println(finger.device_addr, HEX);
Serial.print(F("Packet len: ")); Serial.println(finger.packet_len);
Serial.print(F("波特率: ")); Serial.println(finger.baud_rate);
finger.getTemplateCount();
if (finger.templateCount == 0) {
Serial.print("传感器不包含任何指纹数据。请运行“注册”示例。");
}
else {
Serial.println("等待有效的手指…");
Serial.print("传感器包含 "); Serial.print(finger.templateCount); Serial.println(" 模板");
}
}
void loop() // run over and over again
{
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("拍摄");
break;
case FINGERPRINT_NOFINGER:
Serial.println("没有检测到手指");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("通信错误");
return p;
case FINGERPRINT_IMAGEFAIL:
Serial.println("成像误差");
return p;
default:
Serial.println("未知错误");
return p;
}
// OK success!
p = finger.image2Tz();
switch (p) {
case FINGERPRINT_OK:
Serial.println("图像转换");
return p;
case FINGERPRINT_IMAGEMESS:
Serial.println("图像太乱");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("通信错误");
return p;
case FINGERPRINT_FEATUREFAIL:
Serial.println("找不到指纹特征");
return p;
case FINGERPRINT_INVALIDIMAGE:
Serial.println("找不到指纹特征");
return p;
default:
Serial.println("未知错误");
return p;
}
// OK converted!
p = finger.fingerSearch();
if (p == FINGERPRINT_OK) {
Serial.println("找到匹配的指纹了!");
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
Serial.println("通信错误");
return p;
} else if (p == FINGERPRINT_NOTFOUND) {
Serial.println("没有找到匹配对指纹");
return p;
} else {
Serial.println("未知错误");
return p;
}
// found a match!
Serial.print("找到的 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) {
lcd.setCursor(0,0);
lcd.print("no Finger");
return -1;
}
p = finger.image2Tz();
if (p != FINGERPRINT_OK) {
lcd.setCursor(0,0);
lcd.print("Fingerprint");
lcd.setCursor(0,1);
lcd.print("error");
delay(1000);
lcd.clear();
return -1;
}
p = finger.fingerFastSearch();
if (p != FINGERPRINT_OK) {
lcd.setCursor(0,0);
lcd.print("Fingerprint");
lcd.setCursor(0,1);
lcd.print("error");
delay(1000);
lcd.clear();
return -1;
}
// found a match!
Serial.print("找到的 ID #"); Serial.print(finger.fingerID);
Serial.print(" with confidence of "); Serial.println(finger.confidence);
lcd.setCursor(0,0);
lcd.print("hello");
delay(500);
lcd.clear();
int s=finger.fingerID;
switch(s){
case 2:
lcd.setCursor(0,0);
lcd.print("pt dad");
delay(500);
break;
case 1:
lcd.setCursor(0,0);
lcd.print("llt shi dog");
delay(500);
break;
case 3:
lcd.setCursor(0,0);
lcd.print("ly king");
delay(500);
break;
case 4:
lcd.setCursor(0,0);
lcd.print("wmy si pig");
delay(500);
break;
case 5:
lcd.setCursor(0,0);
lcd.print("wyl king");
delay(500);
break;
case 6:
lcd.setCursor(0,0);
lcd.print("wyh hanpi");
delay(500);
break;
case 8:
lcd.setCursor(0,0);
lcd.print("lwz niubi");
delay(500);
break;
default:
lcd.setCursor(0,0);
lcd.print("lyp king");
delay(500);
break;
}
lcd.setCursor(0,1);
lcd.print(finger.confidence);lcd.print("ms");
delay(1000);
lcd.clear();
int angle = 50;
for ( angle = 0; angle < 180; angle++) //angle+4是舵机的转速设置
{
servopulse(angle);
delay(1);
}
Serial.print("欢迎回家");
lcd.setCursor(0,0);
lcd.print("welcome 504");
lcd.setCursor(0,1);
lcd.print("no Henan home");
delay(3500); //这是拉门的持续时间 3.5秒
for ( angle = 180; angle > 0; angle--)
{
servopulse(angle);
delay(1);
}
lcd.clear();
return finger.fingerID;
}