Home Raspberry Pi Sensors Humidity and Temperature sensor DHT-11 (&DHT-22) for Raspberry Pi and Arduino

Humidity and Temperature sensor DHT-11 (&DHT-22) for Raspberry Pi and Arduino

How to hook up the temperature sensor

Tech details:

  • Supply voltage: 3.3-5V
  • Supply current (running): 0.5mA typ. (2.5mA max.)
  • Supply current (stand-by): 100uA typ. (150uA max.)
  • Temperature range: 0 / +50°C ±2°C Humidity range 20-90%RH ±5%RH
  • Response time: 6 -10 sec for an accurate reading with 2 sec polling time

Connectivity:

3/4* pin connector, pins as follows:

  • VCC: 3.3-5V Supply
  • DATA: Trigger Pulse Input
  • *(3rd pin on 4 pin sensor) NC: Not in use
  • GND: 0V Ground

Pull-up resistor required, or enable pull-up on the RPI – more on pull-up here.

What does it do?

Sensor DHT11 Temperature and Humidity is an indoor solution, as it allows the temperature and humidity measurements within 0-50°C range. If you are interested in taking measurements below 0°C you want to get the twin looking DHT22.  It is taking both measurements,  for temperature and humidity and transmitting this back to the RPI or Arduino board via a digital interface.  This is one of the most popular modules to use due to various possible applications. Think home terrarium, thermostat control etc.  The sensor is quick and able to take independent results within a few seconds if needed.

How to use it?

sensor DHT11 breadboard
sensor DHT11 schematic

The schematics show you, how to connect the sensor DHT11  to the board.  4-10kΩ resistor is advised and it is placed between Data and power (+). You may want to consider a pull-up resistor as well, (if you don’t know what I’m on about read more about resistors) or enable this on your RPI.  Up to 20m cable requires about 5kΩ pull-up, longer leads needs to be checked for resistance. The sensor itself has 4 pins however only 3 of them are used.  Starting from left 1. VCC, 2. Data, 3. Not in use, 4. GND.

When using a 3.5V voltage supply cable length shall not be greater than 20cm. Otherwise, the line voltage drop will cause the sensor power supply shortage, caused by measurement error
sensor DHT11

As one pin isn’t in use, the module itself has 3 pins available and we can connect them directly to 3.3V or 5V  pin. Note that sensor DHT11 allows you to connect the module without using an additional resistor.

Let’s take a look at the ones I have: As supplied from a different manufacturer layout is reversed  (module alone is upside-down). Inspect your module before connecting to avoid damage. Both modules have 10kΩ included.

Understanding the output

Everything so far has been fairly easy to follow and understand. Brace yourself now, we are dealing with a digital interface which returns the data based on the request.  Data returned from the sensor DHT11 has a 40-bit structure: 16 bit for Temp, same for humidity and 8bit verification checksum. This data has to be decoded in order to be presented to us in a readable form. If you are interested in the hard way: look up the data sheet for your sensor ie here.

If you want to use the easy way, there is a library written already, and there is no need to decode all of this again. You can modify the sample script to present you the results as needed.

 Sample code:

Before you test the code there is few things to do:

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

Once the library is downloaded run:

sudo apt-get update
sudo apt-get install build-essential python-dev python-openssl

and then install it on you RPI.

sudo python setup.py install

You can test the temperature using a python2 code from here. Run the DHT11 Class python file first, then open a new file in the same directory and run the sample script.

PayPal

Nothing says "Thank you" better than keeping my coffee jar topped up!

Patreon

Support me on Patreon and get an early access to tutorial files and videos.

image/svg+xml

Bitcoin (BTC)

Use this QR to keep me caffeinated in style with crypto-currency

SATA HAT

Add an SSD to Raspberry Pi 4 and turn it into a super-cooled NAS drive.

More HATs

Argon One

Enclose Raspberry Pi 4 inside this great case with custom I/O, cooling and GPIO

More cases on

Best Raspberry Pi Projects

How to use Raspberry PI as WOL (wake on lan) server

0
While you could wake up your PC from a mobile directly, having a dedicated server capable of doing so is the best solution. The reason is simple. You can hook up as many devices as you wish with a single endpoint. This is why Raspberry Pi is perfect for this.

Free wireless doorbell (Amazon Dash button hack)

0
The most terrifying situation I can imagine* is missing a parcel

Raspberry Pi NAS: (NAS-pi) Modding like a boss #part2

0
Plex and RAID1 NAS drive build log

MagPi – auto-downloader

0
Grab each edition of Mag Pi as soon as possible!

HOW TO...

How to boot Raspberry Pi 4 from USB

0
How to set up and boot Raspberry Pi 4 from USB drive - headless guide.

Raspberry Pi Zero, Raspberry Pi 3A+ WiFi without keyboard or cables

0
Getting Raspberry Pi boards connected in seconds

Everything you need to start using JSON

0
It's JSON not Jason, just saying!

How to use Join App in NodeRED

0
The day finally comes where Join app is almost everywhere!

Driving LCD with Arduino and Raspberry Pi

0
Displaying things on an LCD screen is as easy as going through a cup of jellybeans while writing this tutorial!