Temperature and Humidity Sensor (DHT11)

../../../../_images/dht11_temp_humidity.png

Overview

Based on the DHT11 digital temperature and humidity sensor integrated IC. Used for detecting environmental temperature and humidity.

Technical Specifications

Operating voltage: VCC 3.3V -5V

Module dimensions: 24*48mm

Mounting: 2 plastic building block compatible through-holes

Temperature: -20–60℃

Humidity: 5–95%

Pin Definition

Pin

Definition

GND

Ground

VCC

Power

DI

Digital output

NC

Not connected

Example Code

Print temperature and humidity information every second

from mpython import *

from machine import Timer

import dht

dht11 = dht.DHT11(Pin(Pin.P0))

tim15 = Timer(15)

def timer15_tick(_):
    try: dht11.measure()
    except: pass

tim15.init(period=1000, mode=Timer.PERIODIC, callback=timer15_tick)

import time
while True:
    print(dht11.temperature())
    print(dht11.humidity())
    time.sleep(1)
../../../../_images/dht.png