Đang tải... (xem toàn văn)
Untitled GVHD ThS NGUYỄN TRƯỜNG DUY SVTH TRẦN HOÀNG ANH MSSV 16141104 SVTH TRẦN THỊ MINH THY MSSV 16141301 SKL 0 0 7 8 2 5 BỘ GIÁO DỤC VÀ ĐÀO TẠO TRƯỜNG ĐẠI HỌC SƯ PH M KỸ THUẬT THÀNH PHỐ HỒ CHÍ M NH[.]
BỘ GIÁO DỤC VÀ ĐÀO TẠO TRƯỜNG ĐẠI HỌC SƯ PHҤM KỸ THUẬT THÀNH PHỐ HỒ CHÍ M,NH KHOA KHOA ĐIỆN – ĐIỆN TỬ ĐỒ ÁN TỐT NGHIỆP NGÀNH &1.7Ĉ,ӊ17Ӱ758 debounce) { if (tt5 == "0") { state5 = HIGH; } else if (tt5 == "1") { state5 = LOW; } time5 = millis(); if (state5 == HIGH) { tb5 = "1"; } else if (state5 == LOW) { tb5 = "0"; } } previous1 = reading1; //touch2//điều hịa phịng reading6 = digitalRead(nn6); if (reading6 == HIGH && previous6 == LOW && millis() - time6 > debounce) { if (tt6 == "0") { state6 = HIGH; } else if (tt6 == "1") { state6 = LOW; } time6 = millis(); if (state6 == HIGH) { 101 PHỤ LỤC tb6 = "1"; } else if (state6 == LOW) { tb6 = "0"; } } previous6 = reading6; //touch2//điều hịa phịng reading7 = digitalRead(nn7); if (reading7 == HIGH && previous7 == LOW && millis() - time7 > debounce) { if (tt7 == "0") { state7 = HIGH; } else if (tt7 == "1") { state7 = LOW; } time7 = millis(); if (state7 == HIGH) { tb7 = "1"; } else if (state7 == LOW) { tb7 = "0"; } } previous7 = reading7; } Chương trình ESP8266 #include #include #include #include 102 PHỤ LỤC #include SoftwareSerial mySerial(D2, D1); //rx,tx unsigned long t1 = 0, t2 = 0; String tb1 = "x", tb2 = "x", tb3 = "x", tb4 = "x", tb5 = "x", tb6 = "x", tb7 = "x"; byte moc; String cb1 = "", cb2 = "", cb3 = "", cb4 = ""; String s = "", s1 = "", s2 = ""; String nhiet_do = "", do_am = "", khi_gas = "", chuyen_dong = ""; String st1 = "", st2 = "", st3 = "", st4 = "", st5 = "", st6 = "", st7 = "", st8 = "", stb = ""; int tt1 = 0, tt2 = 0, tt3 = 0, tt4 = 0, tt5 = 0, tt6 = 0, tt7 = 0, tt8 = 0; String ssid = "Aaaaaaaa";//12345679 String password = "231196@96";//12345679 const char* host = "datn2021.online"; const char *hostthietbi = "http://datn2021.online/dktb/text.php"; WiFiClient client; void setup() { Serial.begin(9600); mySerial.begin(57600); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(300); Serial.print("."); } } void loop() { //co tin hieu tu arduino if (mySerial.available()) { char c = mySerial.read(); s += c; 103 PHỤ LỤC if (c == '\n') { s1 = s; s = ""; for (int i = 0; i 500) { // kết nối đến port 80 if (client.connect(host, 80)) { Serial.println("connected"); // truyền liệu lên server theo phương thức get client.print(String("GET http://datn2021.online/insert/insertcb.php?") + ("nhiet-do=") + nhiet_do + ("&do-am=") + do_am + ("&khi-gas=") + khi_gas + ("&chuyen-dong=") + chuyen_dong + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n"); } else { Serial.println("connection failed"); } delay(50); if (client.connect(host, 80)) { Serial.println("connected"); client.print(String("GET http://datn2021.online/insert/inserttb1.php?") + ("&tb1=") + tb1 + ("&tb2=") + tb2 + ("&tb3=") + tb3 + ("&tb4=") + tb4 + ("&tb5=") + tb5 + 106 PHỤ LỤC ("&tb6=") + tb6 + ("&tb7=") + tb7 + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n"); } else { // khơng kết nối với server in kết nối thất bại Serial.println("connection failed"); } //phần cố định delay(50); t1 = millis(); } //nhan du lieu tu database va gui ve arduino if (millis() - t2 > 400) { HTTPClient http; http.begin(hostthietbi); int httpCode = http.GET(); String payload = http.getString(); if (httpCode == 200) { const size_t capacity = JSON_OBJECT_SIZE(3) + JSON_ARRAY_SIZE(2) + 60; DynamicJsonBuffer jsonBuffer(capacity); JsonObject& root = jsonBuffer.parseObject(payload); if (!root.success()) { Serial.println(F("Parsing failed!")); return; } String x1 = root["led"][0]["tb1"]; 107 PHỤ LỤC String x2 = root["led"][0]["tb2"]; String x3 = root["led"][0]["tb3"]; String x4 = root["led"][0]["tb4"]; String x5 = root["led"][0]["tb5"]; String x6 = root["led"][0]["tb6"]; String x7 = root["led"][0]["tb7"]; // String x8 = root["led"][0]["tb8"]; if (x1 == "on") { st1 = "1"; } else if (x1 == "off") { st1 = "0"; } if (x2 == "on") { st2 = "1"; } else if (x2 == "off") { st2 = "0"; } if (x3 == "on") { st3 = "1"; } else if (x3 == "off") { st3 = "0"; } if (x4 == "on") { st4 = "1"; } else if (x4 == "off") { st4 = "0"; } if (x5 == "on") { st5 = "1"; 108 PHỤ LỤC } else if (x5 == "off") { st5 = "0"; } if (x6 == "on") { st6 = "1"; } else if (x6 == "off") { st6 = "0"; } if (x7 == "on") { st7 = "1"; } else if (x7 == "off") { st7 = "0"; } stb = st1 + st2 + st3 + st4 + st5 + st6 + st7; mySerial.println(stb); Serial.println(stb); } else { Serial.println("Error in response"); } http.end(); delay(50); t2 = millis(); } } Chương trình ESP32-CAM #include "esp_camera.h" #include #include 109 PHỤ LỤC // WARNING!!! Make sure that you have either selected ESP32 Wrover Module, // or another board which has PSRAM enabled // // Select camera model //#define CAMERA_MODEL_WROVER_KIT //#define CAMERA_MODEL_ESP_EYE //#define CAMERA_MODEL_M5STACK_PSRAM //#define CAMERA_MODEL_M5STACK_WIDE #define CAMERA_MODEL_AI_THINKER #define SERVO1 12 // Cửa sổ khách #define SERVO2 13 // Cửa sổ khách #include "camera_pins.h" Servo gServo1; Servo gServo2; int pos = 0; Servo myservo; const char* ssid = "Aaaaaaaa"; const char* password = "231196@96"; void startCameraServer(); boolean matchFace = false; boolean activateRelay = false; long prevMillis = 0; int interval = 5000; void ServoOpen() 110 PHỤ LỤC { for (pos = 180; pos >= 0; pos -= 1) { // goes from degrees to 180 degrees // in steps of degree myservo.write(pos); delay(15); // tell servo to go to position in variable 'pos' // waits 15ms for the servo to reach the position } } void ServoClose() { for (pos = 0; pos id.PID == OV3660_PID) { s->set_vflip(s, 1);//flip it back s->set_brightness(s, 1);//up the blightness just a bit s->set_saturation(s, -2);//lower the saturation } //drop down frame size for higher initial frame rate s->set_framesize(s, FRAMESIZE_QVGA); #if defined(CAMERA_MODEL_M5STACK_WIDE) s->set_vflip(s, 1); s->set_hmirror(s, 1); #endif WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } 113 PHỤ LỤC Serial.println(""); Serial.println("WiFi connected"); startCameraServer(); Serial.print("Camera Ready! Use 'http://"); Serial.print(WiFi.localIP()); Serial.println("' to connect"); } void loop() { if (matchFace == true && activateRelay == false) { activateRelay = true; ServoOpen(); delay(5000); ServoClose(); prevMillis = millis(); } if (activateRelay == true && millis() - prevMillis > interval) { activateRelay = false; matchFace = false; } } 114 S K L 0