DHT 11 Sensor

Published by Martin on May 17, 2020

One of my favourite sensors is the DHT11 ( it was my first one I ever got to work ). Its currently running on the old 3 Pis that monitor the computer temperatures. This time I wanted to use it in the Case for measuring the Case Temp and Humidity. It will hang on the wall in the Raspberry Pi Enclosure.

DHT 11 Wiring

This is the original wiring diagram I kept. Its even designed for the Pi1 as its only shows 26 pins !!. The Pull up does seem to appear on some diagrams and then not on others. So make your own choice to install it. I have decided not to wire it on this occasion.

Python Libraries

There is 2 theories on the Libraries required. Circuit Python is the latest and greatest, but currently it fails to read so often I back peddle to the original Legacy Code from github.

Here is the library requirements

sudo apt-get install git-core

git clone https://github.com/adafruit/Adafruit_Python_DHT.git

cd Adafruit_Python_DHT

sudo apt-get install build-essential python-dev

sudo python setup.py install

Python Script

Create this simple script to read the Temperature and Humidity

vi basic-dht11.py


import Adafruit_DHT

humidity, temperature = Adafruit_DHT.read_retry(11, 18 )
if temperature > 0:
        print("DHT11: Temp: {0:0.1f}".format(temperature)+", Humidity: {0:0.1f}".format(humidity))

And run it the same as the BME280

python3 basic-dht11.py

It should produce stats like this :