---
###### tag:`Arduino` `DHT22` `ILI9341`
---
# Arduino 期末考 溫度警示
[TOC]
* 系級:資工三乙
* 座號:16
* 姓名:王君翔
* 指導老師:林宏益
---
## 1.實驗步驟 Steps
* 本次實驗使用[模擬器](https://wokwi.com)進行操作 (With this [Emulator](https://wokwi.com), doing this experiment.)
* 要求:使用DHT22感測器,顯示溫度與濕度量測結果於ILI93412.8吋彩色面板
* 當溫度超過60度,顯示警示畫面(警示畫面可以自由決定)。
* 利用[wowki](https://wokwi.com)完成硬體接線與程式驗證
* requirment: Display the result(temperature & humidity) got from DTH22 on the ILI9341(320x240).
* When the temperature is higher than 60°C, display warning screen.
* Finish the circuit and program with [wowki](https://wokwi.com).
1. 依照電路圖連接電路 (Connect the circuit according to the circuit diagram.)

Δ電路圖 (Circuit Diagram)
2. 將以下程式完成後,透過USB線上傳至Uno板 (After completing the code block below, upload the file to Arduino Uno R3 with USB cable.)
``` C++=
#include <dht.h>
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#define DHT_PIN 5
#define TFT_DC 9
#define TFT_CS 10
dht DHT;
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
double t = 0, h = 0;
void display();
void display2();
void setup() {
tft.begin();
tft.fillScreen(ILI9341_BLACK);
}
void loop() {
if(DHT.read(DHT_PIN) == DHTLIB_OK){
if(DHT.temperature >= 60){
if(t != DHT.temperature || h != DHT.humidity){
t = DHT.temperature;
h = DHT.humidity;
tft.fillScreen(ILI9341_BLACK);
display();
}
}else if(t != DHT.temperature || h != DHT.humidity){
t = DHT.temperature;
h = DHT.humidity;
tft.fillScreen(ILI9341_BLACK);
display2();
}
}
}
void display(){
tft.setCursor(10, 2);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(1);
for(int i = 0; i < 37; i++)
tft.print("-");
tft.setTextSize(3);
tft.setCursor(5, 15);
tft.print("|");
tft.setCursor(60, 15);
tft.print("WARNING");
tft.setCursor(220, 15);
tft.print("|");
tft.setCursor(10, 40);
tft.setTextSize(1);
for(int i = 0; i < 37; i++)
tft.print("-");
tft.setCursor(10, 50);
for(int i = 0; i < 37; i++)
tft.print("-");
tft.setCursor(10, 315);
for(int i = 0; i < 37; i++)
tft.print("-");
for(int i = 52; i < 314; i++){
tft.setCursor(10, i);
tft.print("|");
tft.setCursor(225, i);
tft.print("|");
}
tft.setTextColor(ILI9341_YELLOW);
tft.setCursor(20, 70);
tft.setTextSize(2);
tft.print("Temperature: ");
tft.setTextColor(ILI9341_RED);
tft.setCursor(20, 90);
tft.print(t);
tft.print(" ");
tft.setTextSize(1);
tft.print("o");
tft.setTextSize(2);
tft.print("C");
tft.setTextColor(ILI9341_YELLOW);
tft.setCursor(20, 130);
tft.print("Humidity: ");
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(20, 150);
tft.print(h);
tft.print(" %");
tft.setTextColor(ILI9341_YELLOW);
tft.setCursor(20, 190);
tft.print("Current");
tft.setCursor(20, 210);
tft.print("Temperature");
tft.setCursor(20, 230);
tft.print("Is Higher Than");
tft.setCursor(20, 250);
tft.setTextColor(ILI9341_RED);
tft.print("60 ");
tft.setTextSize(1);
tft.print("o");
tft.setTextSize(2);
tft.print("C");
tft.setTextColor(ILI9341_YELLOW);
tft.print(".");
}
void display2(){
tft.setTextSize(1);
tft.setTextColor(ILI9341_GREEN);
tft.setCursor(10, 50);
for(int i = 0; i < 37; i++)
tft.print("-");
tft.setCursor(10, 315);
for(int i = 0; i < 37; i++)
tft.print("-");
for(int i = 52; i < 314; i++){
tft.setCursor(10, i);
tft.print("|");
tft.setCursor(225, i);
tft.print("|");
}
tft.setTextColor(ILI9341_YELLOW);
tft.setCursor(20, 70);
tft.setTextSize(2);
tft.print("Temperature: ");
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(20, 90);
tft.print(t);
tft.print(" ");
tft.setTextSize(1);
tft.print("o");
tft.setTextSize(2);
tft.print("C");
tft.setTextColor(ILI9341_YELLOW);
tft.setCursor(20, 130);
tft.print("Humidity: ");
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(20, 150);
tft.print(h);
tft.print(" %");
}
```
3. 進行模擬並紀錄實驗結果。 (Start simulation and record the result)
---
## 2.實驗結果 Result

Δ接線完成圖 (Finished Circuit)

<br>

Δ運作圖 (Working)
[Link to my work](https://wokwi.com/projects/334509886070063698)
---