HomeRaspberry Pi SensorsHumidity 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


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.


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


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


Bitcoin (BTC)

Use this QR to keep me caffeinated with BTC: 1FwFqqh71mUTENcRe9q4s9AWFgoc8BA9ZU


Programable, ESP32 based awesome dev platform with 4.7 e-ink display by M5Stack

More HATs


Argon One M.2

Enclose Raspberry Pi 4 inside this great case with custom I/O, cooling and GPIO and M.2 SSD support

More cases on


Best Raspberry Pi Projects

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

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.

Slow Internet Warning

From time to time my Internet grinds to a stop. Since Raspberry Pi 4 comes with a 1Gbps Ethernet, I decided to take advantage of it and create a reporting system in NodeRED that will monitor and report when the ISP is not keeping the contractual agreements. Works with Alexa, Google Home, Android and Windows 10.

How fast Raspberry Pi NAS is?

Let's see how fast Raspberry Pi NAS really is?

Argon18: Argon ONE SSD modification

Argon One case just got better - now you can boot it from USB without ruining the design thanks to Argon 18: Argon One SSD modification


It took me 2 months to boot CM4 from NVMe

Complete beginners guide to Compute Module 4 boot from NVMe.

Raspberry Pi Zero 2 W vs other Zero boards

It's time to test the Raspberry Pi Zero 2 W against other Raspberry Pi boards from Zero series: power, WiFi, temperature and core performance

C/C++ and MicroPython SDK for Raspberry Pi Pico on Windows

A guide to SDK toolchain for Raspberry Pi Pico and C/C++ , Micropython on Windows.

A comprehensive guide to Grafana & InfluxDB

How to use Grafana and InfluxDB on Raspberry Pi for IoT sensors in home automation

How to boot Raspberry Pi 4 from USB

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