Welcome to MicroPython DHT12 Library’s documentation!¶
Contents:
dht12 module¶
DHT12¶
-
class
dht12.
DHT12
(i2c[, address])¶ The basic class for handling the communication with the sensor.
The
i2c
parameter is an initialized I²C bus, and the optional address specifies which sensor to connect to, if you have more than one and have changed their addresses with theAddr
pin.-
temperature
()¶ Get the temperature in Celcius
-
humidity
()¶ Get the relative humidity as a percentage
-
Usage Examples¶
Connect your sensor in following way:
vin
↔3V
sda
↔gpio4
gnd
↔gnd
scl
↔gpio5
Now, to make basic measurement:
import dht12
from machine import I2C, Pin
i2c = I2C(scl=Pin(5), sda=Pin(4))
sensor = dht12.DHT12(i2c)
sensor.measure()
print(sensor.temperature())
print(sensor.humidity())
To perform continuous measurement:
import time
while True:
sensor.measure()
print(sensor.temperature())
print(sensor.humidity())
time.sleep_ms(4000)