8074| 9
|
[项目] 用电磁锁做一个指纹锁 |
本帖最后由 hnyzcj 于 2019-6-14 17:10 编辑 入手DF商城的指纹传感器和阿里套件的电磁锁有段时间了,一直没有动过,所以这次把这两样东西放在一起玩玩! 【展示视频】 【展示效果】 【作品器材】 DFRduino UNO R3 1 IO 传感器扩展板 V7.1 1 指纹识别传感器 1 电磁锁 1 数字继电器模块 1 I2C LCD1602液晶模块(兼容Arduino Gadgeteer) 1 M3*30扁头内六角螺丝 10套 1 【制作过程】 1.3D建模盒子结构件 3D打印模型 3D打印盒子结构件 3D打印盒子盖 3D打印盒子 (新模型盒盖和盖轴是连在一起的) 器材安装 拿出电磁锁和三根M3的螺丝 将电磁锁安装盒壁的侧面 拿出指纹传感器从盒子内部由里到外穿出指纹传感器,使其卡在指纹传感器的卡缝处。用热熔胶枪从盒子内部打胶固定指纹传感器。 用AB胶水固定在盖板上,用30mm的m3螺丝固定转轴。 再将LCD屏固定在对应的孔位上。 把主控器等电子元器件放入盒子内部。 电路连线图: 代码编写: [mw_shl_code=cpp,true] #include <Arduino.h> #include <SoftwareSerial.h> #include <Wire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x20,16,2); // set the LCD address to 0x20 for a 16 chars and 2 line display #include <Adafruit_Fingerprint.h> SoftwareSerial mySerial(2, 3); Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); void setup() { lcd.init(); // initialize the lcd lcd.home(); lcd.print("door use finger"); lcd.setCursor(0, 1); lcd.print("nsfzsz_cj"); 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); pinMode(4, OUTPUT); pinMode(6, INPUT_PULLUP); //Set Pin6 as output 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..."); } 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 { getFingerprintIDez(); delay(50); //don't ned to run this at full speed. //lcd.print("read your finger"); } 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) { // digitalWrite(12,LOW); Serial.println("Communication error"); return p; } else if (p == FINGERPRINT_NOTFOUND) { //digitalWrite(12,LOW); Serial.println("Did not find a match"); return p; } else { //digitalWrite(12,LOW); Serial.println("Unknown error"); return p; } // found a match! // digitalWrite(12,HIGH); 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; lcd.clear(); lcd.print("you no master"); p = finger.image2Tz(); if (p != FINGERPRINT_OK) return -1; lcd.clear(); lcd.print("you no master"); p = finger.fingerFastSearch(); if (p != FINGERPRINT_OK) return -1; // found a match! lcd.clear(); lcd.print("Found ID #"); lcd.print(finger.fingerID); lcd.setCursor(0, 1); lcd.print("come in master"); //lcd.print(finger.confidence); digitalWrite(4,HIGH); delay(5000); digitalWrite(4,LOW); lcd.clear(); //Serial.print("Found ID #"); // Serial.print(finger.fingerID); //Serial.print(" with confidence of "); Serial.println(finger.confidence); return finger.fingerID; }[/mw_shl_code] 测试效果: 整体效果 上电效果,输入指纹开门 输入错误的指纹 输入正确的指纹信息 |
gada888 发表于 2019-6-20 07:15 学习中,希望自己能成功做出一个来!谢谢分享! |
dsweiliang 发表于 2019-6-19 09:38 加一个按钮。或者通过指纹模块感应信号:https://mc.dfrobot.com.cn/thread-297288-1-1.html (这里没有明确说明) |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed