Final 期末報告 === 使用DHT22偵測濕度及溫度 --- **資工三乙 許琮靖** **指導老師: 林宏益 老師** --- #### wowki可執行程式連結 [https://wokwi.com/projects/335342195765674579](https://) --- ### 程式碼 ``` #include "dht.h" #define DHTPIN 2 #include "SPI.h" #include "Adafruit_GFX.h" #include "Adafruit_ILI9341.h" #define TFT_DC 9 #define TFT_CS 10 Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); dht DHT; void setup() { tft.begin(); } void loop() { delay(500); tft.fillScreen(ILI9341_BLACK); float temp = DHT.temperature; float hum = DHT.humidity; if(DHT.read(DHTPIN) == DHTLIB_OK){ tft.setTextColor(ILI9341_BLUE); tft.setTextSize(3); tft.setCursor(26, 120); tft.print("Temp:"); tft.print(temp); tft.println("c"); tft.print(" RH:"); tft.print(hum); tft.println("%"); if(temp >= 60 ){ tft.setTextColor(ILI9341_RED); tft.setTextSize(4); tft.println(" WAREING!"); tft.setTextSize(2); tft.println("The temperature over 60"); } } } ``` --- ### ArduinoUNO接線圖 ![](https://i.imgur.com/gfk92jz.png)