Skip to content

1.DHT Sensor Setup

Sambhav edited this page Aug 31, 2018 · 3 revisions

The DHT11 is a low-cost temperature and humidity sensor. It isn’t the fastest sensor around but its cheap price makes it useful for experimenting or projects where you don’t require new readings multiple times a second. The device only requires three connections to the Pi. +3.3v, ground and one GPIO pin.

Hardware Specifications

he 3-pin modules will usually have this resistor included which makes the wiring a bit easier. For this reason I got hold of the module which I could then attach to the Pi with a piece of 3-way Dupont cable.

Different suppliers may wire the module pins differently so check the PCB markings to identify Vcc (+), data or out and Ground (-).

The 3 pins should be connected to the Pi as shown in the table below :

3.3V - + pin of DHT11 module

Gnd - - pin of DHT11 module

Pin17- out pin of DHT11 module

Python Library

The DHT11 requires a specific protocol to be applied to the data pin. In order to save time trying to implement this yourself it’s far easier to use the Adafruit DHT library.

The library deals with the data that needs to be exchanged with the sensor but it is sensitive to timing issues. The Pi’s operating system may get in the way while performing other tasks so to compensate for this the library requests a number of readings from the device until it gets one that is valid.

Software Setup

First lets clone the Adafruit Library from their repositary:

Open Terminal and paste the following:

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

cd Adafruit_Python_DHT

Then install the library for python:

sudo python setup.py install

Adafruit Example Python Script

Adafruit provides an example script which can be used to check if the sensor is operating correctly

cd ~

cd Adafruit_Python_DHT

cd examples

Then:

python AdafruitDHT.py 11 17

Using the Library in other Python Scripts

The link for the code is given here

Run using:

python dht11.py

Source: Raspberry-spy.co.uk

Clone this wiki locally