dht — dht module

The dht module provides functions related to reading the dht series of temperature and humidity sensors.

class DHT22

Constructors

class DHT22(pin)

Create a DHT22 sensor object connected to the pin.

  • pin: the 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 of the sensor.

Example:

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

Read and return the temperature value of the sensor.

Example:

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

class DHT11

Similar to the DHT22() function, so it is not repeated here.