dht — DHT Module

The dht module provides functions for reading DHT series temperature and humidity sensors.

Class DHT22

Constructors

class DHT22(pin)

Create a DHT22 sensor object connected to the specified pin.

  • pin: pin

Supported Pins

  • ESP32: GPIO0/2/4/5/16/17/18/19/21/22/23/25/26/27

  • mPython Board: P0/1/8/9/13/14/15/16

Example:

from machine import Pin
import dht

d = dht.DHT22(Pin(Pin.P0))

Methods

DHT22.humidity()

Read and return the humidity value from the sensor.

Example:

d.measure()
print(d.humidity())
DHT22.temperature()

Read and return the temperature value from the sensor.

Example:

d.measure()
print(d.temperature())

Class DHT11

Similar to the DHT22() class, not repeated here.