1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
| #include <DFRobot_DHT11.h> DFRobot_DHT11 DHT; #define DHT11_PIN A2 // 对应的是A0引脚 #include <Adafruit_Fingerprint.h> //声明调用Adafruit_Fingerprint.h库 指纹 #include <Servo.h> // 声明调用Servo.h库 舵机 Servo myservo; // 创建一个舵机对象 int pos = 0; // 变量pos用来存储舵机位置 const int servoDelay = 15; const int servoStop = 2000; const int lowPowerRate = 1; const int checkDelay = 1000; const int debug = 0; int beep = 6;//定义数字口6控制蜂鸣器 int red = 5;//定义数字口5 /*光感*/ #define lightR A0 #define LED 13 /*光感*/
SoftwareSerial mySerial(2, 3);//黄色串行数据输出&&白色串行数据输入接口(可修改范围A0~A5,2~13) Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); void setup() { pinMode(7, OUTPUT); pinMode(8, OUTPUT); pinMode(LED,OUTPUT); //设置连接小灯的引脚为输出模式 pinMode(lightR,INPUT); pinMode(beep,OUTPUT);//设置数字6引脚为输出模式 pinMode(red,OUTPUT);//设置数字6引脚为输出模式 myservo.attach(9); //舵机信号端口(可修改范围A0~A5,2~13) myservo.write(0); Serial.begin(9600); Serial.println("Demo Start"); while (!Serial); // For Yun/Leo/Micro/Zero/... delay(100); Serial.println("\n\nAdafruit finger detect test"); finger.begin(57600);//设置传感器串行端口的数据速率 delay(5); if (finger.verifyPassword()) { Serial.println("Found fingerprint sensor!"); } else { Serial.println("Did not find fingerprint sensor :("); while (1) { delay(1); } } Serial.println(F("Reading sensor parameters")); finger.getParameters(); Serial.print(F("Status: 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("Security level: ")); Serial.println(finger.security_level); Serial.print(F("Device address: ")); Serial.println(finger.device_addr, HEX); Serial.print(F("Packet len: ")); Serial.println(finger.packet_len); Serial.print(F("Baud rate: ")); Serial.println(finger.baud_rate); finger.getTemplateCount(); if (finger.templateCount == 0) { Serial.print("Sensor doesn't contain any fingerprint data. Please run the 'enroll' example."); } else { Serial.println("Waiting for valid finger..."); Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates"); } } void loop() // run over and over again { huoyanbaojing(); wenshiducaiji(); fengshan(); Serial.println("Voltage in 4"); Serial.println(digitalRead(4)); if(!lowPowerRate || digitalRead(4) == HIGH) { getFingerprintID(); } delay(checkDelay); //don't ned to run this at full speed. guanggan(); } void openAndReset(){ for(pos = 0; pos < 90; pos += 1){ // 舵机从0°转到180°,每次增加1° myservo.write(pos); // 给舵机写入角度 delay(servoDelay); // 延时15ms让舵机转到指定位置 } delay(servoStop); for(pos = 90; pos>=1; pos-=1) { // 舵机从180°转回到0°,每次减小1° myservo.write(pos); // 写角度到舵机 delay(servoDelay); // 延时15ms让舵机转到指定位置 } } 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; } 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; } p = finger.fingerSearch(); if (p == FINGERPRINT_OK) { Serial.println("Found a print match!"); digitalWrite(beep,LOW);//关闭蜂鸣器 } else if (p == FINGERPRINT_PACKETRECIEVEERR) { Serial.println("Communication error"); return p; } else if (p == FINGERPRINT_NOTFOUND) { digitalWrite(red,HIGH);//提示红灯 Serial.println("Did not find a match"); digitalWrite(beep,HIGH);//打开蜂鸣器 delay(1000); digitalWrite(beep,LOW);//打开蜂鸣器 return p; } else { Serial.println("Unknown error"); return p; } Serial.print("Found ID #"); Serial.print(finger.fingerID); Serial.print(" with confidence of "); Serial.println(finger.confidence); openAndReset(); return finger.fingerID; }
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! Serial.print("Found ID #"); Serial.print(finger.fingerID); Serial.print(" with confidence of "); Serial.println(finger.confidence); return finger.fingerID; }
//光感函数 void guanggan(){ int val=analogRead(lightR); //读取模拟接口A0的值,也就是14号口,把值赋给val Serial.println("光感模拟量值为:"); //显示字符串"模拟量值为:" Serial.println(val); //通过串口打印对应的val值,并且通过串口进行显示出来 delay(1000);//延时1秒 if(val>100)//判断是否大于设定值 { digitalWrite(LED,HIGH);//点亮led //digitalWrite(beep,LOW);//关闭蜂鸣器 }else{ digitalWrite(LED,LOW);//关闭led //digitalWrite(beep,HIGH);//打开蜂鸣器 } }
//可燃检测 void huoyanbaojing() { int vall = analogRead(A1);//读取模拟14口的值 Serial.println("可燃模拟量值为:"); //显示字符串"模拟量值为:" Serial.println(vall); //读取模拟接口A0的值,并且通过串口进行显示出来 if(vall>1000)//可以通过调节这个参数来改变火焰检测的阀值 { Serial.print("环境正常"); digitalWrite(red,LOW);//关闭提示灯 digitalWrite(beep,LOW);//关闭蜂鸣器 } else//否则 { Serial.print("环境异常"); digitalWrite(red,HIGH);//打开提示灯 digitalWrite(beep,HIGH);//打开蜂鸣器 openAndReset(); delay(1000); digitalWrite(red,LOW);//关闭提示灯 } delay(1000); }
void wenshiducaiji(){ delay(1000); DHT.read(DHT11_PIN); float RH = DHT.humidity; //读取湿度数据 float T = DHT.temperature; //读取温度数据 Serial.print("Humidity:"); //向串口打印 Humidity: Serial.print(RH); //向串口打印湿度数据 Serial.print("%"); Serial.print(" Temperature:"); Serial.print(T); //向串口打印温度数据 Serial.println("C"); if(T<33)//可以通过调节这个参数来改变火焰检测的阀值 { Serial.print("温度正常"); digitalWrite(red,LOW);//关闭提示灯 digitalWrite(beep,LOW);//关闭蜂鸣器 } else//否则 { Serial.print("温度异常"); digitalWrite(red,HIGH);//打开提示灯 //digitalWrite(beep,HIGH);//打开蜂鸣器 openAndReset();//开门 delay(1000); digitalWrite(red,LOW);//关闭提示灯 } delay(500); //延时1000毫秒 }
void fengshan(){ int valll = analogRead(A3); Serial.println(" "); Serial.println("模拟量值为: "); Serial.println(valll); if (valll < 600) { digitalWrite(7,HIGH); digitalWrite(8,LOW); } else { digitalWrite(7,LOW); digitalWrite(8,LOW); } //delay(500); }
|