Run the code found in the chapter09/dht_measure.py file, and the measured temperature and humidity will be printed to your terminal, similar to the following:
(venv) python DHT_Measure.py
{'temp_c': 21, 'temp_f': 69.8, 'humidity': 31, 'valid': True}
Here, we have the following:
- temp_c is the temperature in degrees Celsius.
- temp_f is the temperature in degrees Fahrenheit.
- humidity is the relative humidity percentage.
- valid indicates whether the reading is considered valid by way of an internal sensor checksum check. Readings where value == False must be abandoned.
The code in the source file is concise and is fully replicated here.
In line 1, we import the DHT sensor library and instantiate it in line 2. Update the line to match the DHT11 or DHT22 sensor you are using:
from pigpio_dht import DHT11, DHT22 # (1)
SENSOR_GPIO = 21
sensor = DHT11(SENSOR_GPIO) # (2)
#sensor = DHT22(SENSOR_GPIO...