# 溫溼度感測模組

![](https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LaZQFBYOS3O0ksiEmR1%2F-MITXE27AFG-0fjUYfrM%2F-MITXTD6ZQefrrdolSmM%2FTemp.jpg?alt=media\&token=695e08af-af75-4105-8994-38f3a8e4e51e)

## **指令**

![](https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LaZQFBYOS3O0ksiEmR1%2F-MITS8FA8hoJEo5HvugB%2F-MITSeCEie_cZ4k6_jUr%2FLesson_8_TemperatureHumiditySensor2.png?alt=media\&token=bd997f1f-aa92-419c-9b9a-4b0195d44060)

## **對應的**Arduino 語法

```
    dht11_p3.readTemperature();
    dht11_p3.readHumidity();
```

### 範例 BlocklyDuino 積木畫布

在OLED顯示模組上顯示溫溼度感測模組的溫度和濕度。

![](https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LaZQFBYOS3O0ksiEmR1%2F-MITS8FA8hoJEo5HvugB%2F-MITSu6qvRKO1NNVVbTd%2FLesson_8_TemperatureHumiditySensor.png?alt=media\&token=99ef2ee3-2dcf-4b99-b5f9-7462590ea684)

## Arduino 程式

```
#include "DHT.h"
DHT dht11_p3(3, DHT11);

#include <Arduino.h>
#include <U8x8lib.h>
U8X8_SSD1306_128X64_ALT0_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE);

float temp;

float humi;

void setup()
{
  u8x8.begin();
  u8x8.setFlipMode(1);u8x8.setFont(u8x8_font_chroma48medium8_r);

}


void loop()
{
  temp = (dht11_p3.readTemperature());
  humi = (dht11_p3.readHumidity());
  u8x8.setCursor(0, 33);
  u8x8.print(String() + "Temp:" + temp + "C");
  u8x8.setCursor(0, 50);
  u8x8.print(String() + "Humi:" + humi + "%");
  delay(200);
}
```

## 影片教學:

{% embed url="https://www.youtube.com/watch?v=bAbHAfYffQ0" %}

