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
| #include"rfid1.h" #include "Adafruit_MLX90614.h" #include "LiquidCrystal_I2C.h" #include <Wire.h> //调用库文件 #define uchar unsigned char #define uint unsigned int #define ull unsigned long long #define Red 45 #define Green 47 #define Yellow 49 #define Buzzer 2 #define Relay 5 #define IRQ 10 #define SCK 8 #define MOSI 9 #define MISO 11 #define SDA 7 #define RST 12 RFID1 rfid; Adafruit_MLX90614 mlx = Adafruit_MLX90614(); LiquidCrystal_I2C lcd(0x27,16,2); uchar serNum[5]; uchar a; uint b; double tem; void setup() { Serial.begin(9600); Serial2.begin(9600); pinMode(Buzzer,OUTPUT); pinMode(Relay,OUTPUT); pinMode(Red,OUTPUT); pinMode(Yellow,OUTPUT); pinMode(Green,OUTPUT); rfid.begin(IRQ,SCK,MOSI,MISO,SDA,RST); mlx.begin(); rfid.init(); lcd.init(); lcd.backlight(); lcd.print(" Smart-lock "); } void TEM() { Serial.println(mlx.readObjectTempC()+5); tem=mlx.readObjectTempC()+5; return tem+5; } void open() { if(tem<=37.3) { lcd.clear(); lcd.setCursor(0,0); lcd.print("Temperature OK"); lcd.setCursor(0,1); lcd.print("Temp is: "); lcd.print(tem); lcd.print("*C"); Serial.println("Temperature OK"); Serial2.println("Temperature OK"); Serial.print("Turn on."); Serial2.print("Turn on."); digitalWrite(Red,LOW); digitalWrite(Green,HIGH); digitalWrite(Relay,LOW); digitalWrite(Buzzer,LOW); delay(100); digitalWrite(Buzzer,HIGH); delay(100); digitalWrite(Buzzer,LOW); delay(100); digitalWrite(Buzzer,HIGH); digitalWrite(Relay,HIGH); digitalWrite(Green,LOW); digitalWrite(Red,HIGH); lcd.clear(); lcd.setCursor(0,0); lcd.print(" Smart-lock "); Serial.print("Turn off."); Serial2.print("Turn off."); } else { lcd.clear(); lcd.setCursor(0,0); lcd.print("Temperature HIGH"); lcd.setCursor(0,1); lcd.print("Temp is: "); lcd.print(tem); lcd.print("*C"); Serial.println("Temperature HIGH"); Serial2.println("Temperature HIGH"); digitalWrite(Red,LOW); digitalWrite(Yellow,HIGH); delay(100); digitalWrite(Yellow,LOW); delay(100); digitalWrite(Yellow,HIGH); delay(100); digitalWrite(Yellow,LOW); digitalWrite(Red,HIGH); digitalWrite(Buzzer,LOW); delay(100); digitalWrite(Buzzer,HIGH); delay(100); digitalWrite(Buzzer,LOW); delay(100); digitalWrite(Buzzer,HIGH); delay(100); digitalWrite(Buzzer,LOW); delay(100); digitalWrite(Buzzer,HIGH); lcd.clear(); lcd.print(" Smart-lock "); } } void loop() { uchar status; uchar str[MAX_LEN]; digitalWrite(Relay,HIGH); digitalWrite(Buzzer,HIGH); digitalWrite(Red,HIGH); digitalWrite(Yellow,LOW); digitalWrite(Green,LOW); TEM(); status = rfid.request(PICC_REQIDL, str); rfid.showCardType(str); status=rfid.anticoll(str); if(status==MI_OK) { Serial.print("The card's number is: "); memcpy(serNum,str,SCK); rfid.showCardID(serNum); Serial.println(); Serial.println(); } uchar* id=serNum; if(Serial2.available()>0) { a=Serial2.read(); b=1; } if(id[0]==0xCA && id[1]==0xD9 && id[2]==0xF0 && id[3]==0x3F) { open(); for(int i=0;i<=3;i++) id[i]=0; for(int i=0;i<=3;i++) serNum[i]=0; } else { if(status==MI_OK) { lcd.clear(); lcd.println("Password Error"); digitalWrite(Yellow,HIGH); digitalWrite(Green,HIGH); digitalWrite(Buzzer,LOW); delay(3000); digitalWrite(Buzzer,HIGH); digitalWrite(Yellow,LOW); digitalWrite(Green,LOW); lcd.clear(); lcd.print(" Smart-lock "); } } if(a=='a') { b=0; open(); } else { if(b==1) { lcd.clear(); lcd.println("Password Error"); digitalWrite(Yellow,HIGH); digitalWrite(Green,HIGH); digitalWrite(Buzzer,LOW); delay(3000); digitalWrite(Buzzer,HIGH); digitalWrite(Yellow,LOW); digitalWrite(Green,LOW); lcd.clear(); lcd.println("Password Error"); } } rfid.halt(); }
|