DHT11

From Sketching with Hardware at LMU Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

The DHT11 is a temperature and humidity sensor.

Reading Values using MicroPython

import machine
import time
import dht

DHT_PIN = 25
sensor = dht.DHT11(machine.Pin(DHT_PIN))

while (True):
    sensor.measure()
    humidity = sensor.humidity()
    temperature_C = sensor.temperature()

    print("Humidity: {:.1f}%  |  Temperature: {:.1f}°C".format(humidity, temperature_C))
    
    except OSError as e:
        print("Failed to read from DHT sensor! {}".format(e))

    time.sleep(2)

External links