---
# System prepended metadata

title: Arduino 期末考 溫度警示

---

# Arduino 期末考 溫度警示

## 學生：
資工三乙柯振昇

## 實驗材料：
wokwi.com

## 實驗步驟：
溫度濕度警報器

## 程式碼 溫度濕度警報器
```c=
#include "DHT.h"

#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
#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);
float h=0,t=0;
void setup() {
  tft.begin();
  dht.begin();
  tft.fillScreen(ILI9341_BLACK);
  
}
float o=0,p=0;
void loop() { 
  delay(2000);
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  if(o!=dht.readTemperature() || p!=dht.readHumidity()){
    tft.fillScreen(ILI9341_BLACK);
  }
  tft.setCursor(26, 120);
  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(3);
  tft.print("H:");
  tft.println(h);
  
  tft.setCursor(20, 160);
  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(3);
  tft.print("%C:");
  tft.println(t);
  tft.setCursor(14, 200);
  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(3);
  if(t>=60){
     tft.print("high");
  }
  if(t<60){
      tft.print("nice");
  }
  o=t;
  p=h;
}
```
## 實驗結果
### 接線
![](https://i.imgur.com/bBQSrG4.png)


### 溫度太高
![](https://i.imgur.com/oXOrJbk.png)

### 溫度適合
![](https://i.imgur.com/izCPVmU.png)




## wokwi連結
(https://wokwi.com/projects/336093372888384084)