Earn Maker Points on Every Order! Learn More!

DHT11 Temperature and Humidity Sensor with Raspberry Pi | Python

Back to Blog
DHT11 Temperature and Humidity Sensor with Raspberry Pi | Python - DHT11 Temperature and Humidity Sensor with Raspberry Pi | Python - DHT11 Temperature and Humidity Sensor with Raspberry Pi | Python - DHT11 Temperature and Humidity Sensor with Raspberry Pi | Python

DHT11 Temperature and Humidity Sensor with Raspberry Pi | Python

DHT11 is one of the most used Temperature and Humidity Sensor. It is cheap, compact and provides a reliable data, it is best for a DIY electronics projects.

The DHT11 can measure Temperature between 0 to 50° C with ±2 °C accuracy. It can measure Humidity between 20 to 80% with ±5% accuracy. The sampling rate of DHT11 is 1 HZ which is 1 reading per second. The Operating Voltage of DHT11 is 3 to 5V and uses a 2.5 mA of maximum current while operating.

The DHT11 Temperature and Humidity Sensor consist of 3 main components. A resistive type humidity sensor, an NTC (negative temperature coefficient) thermistor (to measure the temperature) and an 8-bit microcontroller, which converts the analog signals from both the sensors and sends out single digital signal.

Distance up to 20 m**

How DHT11 Measures Temperature?

For measuring Temperature the sensor uses an NTC Thermistor. A Thermistor is a variable resistor that changes its resistance to the change in temperature. The NTC means Negative Temperature Coefficient which means resistance decreases as temperature rises.

A thermistor is made of metallic oxides which is pressed into a bead, disk, or cylindrical shape and then encapsulated with an impermeable material such as epoxy or glass.

How DHT11 Measures Humidity?

The Humidity is measured by the electrical resistance between two electrodes. The humidity sensing component of the DHT11 is a moisture holding substrate (usually a salt or conductive plastic polymer) with the electrodes applied to the surface. The ions are released by the substrate as water vapor is absorbed by it, which in turn increases the conductivity between the electrodes. The change in resistance between the two electrodes is proportional to the relative humidity.

Circuit Diagram:

DHT11 with Raspberry Pi

Note: There are different DHT11 modules available in the Market. Make sure the Signal, VCC and Ground are properly connected to Raspberry Pi. The OUT pin is mentioned as SIG in few modules and also the position of pin varies.

Here we have the DHT11 with VCC-OUT-GND. So we connected the middle pin to Raspberry Pi 23rd GPIO Pin.

 

DHT11 SensorRaspberry Pi
VCC5 V
OUT/SIGGPIO23
GNDGND

 

DHT11 using AdaFruit DHT11 Library for Raspberry Pi:

Adafruit developed a simple library to use DHT11 with Python. So we need to install the library from GitHub. Before that, we need to install Git if you are not installed.

Step 1: Open the terminal and use the following command to install Git.

sudo apt-get install git-core

Step 2: Now we need to install the Adafruit DHT11 Library. Use the command to download the Adafruit DHT11 Library from Git.

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

Step 3: Now navigate to the ‘Adafruit_Python_DHT11’ directory using the following command.

cd Adafruit_Python_DHT

Step 4: Now enter this command

sudo apt-get install build-essential python-dev

Step 5: Install the Adafruit DHT11 library now.

sudo python setup.py install

Step 6: Now we need to configure the Pin for Pi.

Navigate to the example file using the command

cd examples

Step 7: Open the file using nano editor.

nano simpletest.py

This will open the text editor. Choose the pin you connected the DHT11 with Raspberry Pi.

By default, it is selected for BeagleBone. So Change the Pin for Pi by comment (put #) the Beaglebone Pin and Uncomment (remove #) the Raspberry Pi GPIO Pin.

6.Change Pin for Pi

 

 

6b.Configured Pi Pin

Save the File by pressing ‘Ctrl X’. Then press y to save.

Step 8: Now run the file by using the command,

python simpletest.py

You can able to see the Temperature and Humidity in the terminal.

Share this post

Comments (5)

  • Rusty

    I’m new to python and have this error… can you please help..

    When I get to stage 5
    sudo python setup.py install

    I get this error…

    Traceback (most recent call last):
    File “setup.py”, line 1, in
    from setuptools import setup, find_packages, Extension
    ImportError: No module named setuptools

    May 1, 2019 at 5:08 PM
  • Sharath

    A setup.py package is needed. Use the following commnad and try again.

    sudo apt-get install python-setuptools

    For Python 3.X

    sudo apt-get install python3-setuptools

    May 2, 2019 at 2:23 PM
  • manoj

    Failed to get reading. Try again! this error show

    May 15, 2019 at 3:58 PM
  • jeevan

    How to controll the over heat protection auto cutoff circuit baker, I used DHT11 Sensor for room temperature auto cutoff chemni for detections Humidity & Temperature with auto ON & OFF but the value of serial print code was not working how to read the Serial data for DHT11 Sensor relay ON & OFF based on temperature & humidity.

    http://bigbelectronics.in/product.php?product=dht11-temperature-and-humidity-sensor-module-arduino-raspberry-pi

    November 23, 2019 at 11:12 AM

Leave a Reply

Back to Blog