> For the complete documentation index, see [llms.txt](https://nkust.gitbook.io/micro-bit/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nkust.gitbook.io/micro-bit/micropython-dht11-du-gan-qi.md).

# MicroPython DHT11溫濕度感測器

在嵌入式系統中常見的溫濕度感測器DHT11，在micro:bit中也可以使用MicroPython來完成量測的程式。這次我們使用是以下的這個模組：

{% embed url="<https://github.com/rhubarbdog/microbit-dht11>" %}

同樣地，請下載之後解壓縮，然後把dht11.py上傳到micro:bit板子上，利用以下的程式即可讓micro:bit的LED顯示器以捲動的方式顯示出目前正確的環境溫濕度：

```python
from microbit import *
from dht11 import DHT11

while True:
    sensor = DHT11(pin0)
    t, h = sensor.read()
    display.scroll("{}C,{}%".format(t, h))
    sleep(2000)
```
