Random Nerd Tutorials

Complete Guide for DHT11/DHT22 Humidity and Temperature Sensor With Arduino


This post aims to be a complete guide for the popular DHT11/DHT22. I’ll explain how it works, show some features and share an Arduino Project example that you can take and apply to your own projects.

I have more complete guides for other popular sensors, check them below:


These DHTXX sensors are very popular among the Arduino Tinkerers. The DHT sensors are inexpensive sensors for measuring temperature and humidity.

These sensors contain a chip that does analog to digital conversion and spits out a digital signal with the temperature and humidity.

These signals are easy to read with any microcontroller (MCU).

humidity sensor

Specifications DHT11 vs DHT22

There are two versions of the DHT sensor.


  • Range: 20-90%
  • Absolute accuracy: ±5%
  • Repeatability: ±1%
  • Long term stability: ±1% per year
  • Price: $1 to $5


  • Range: 0-100%
  • Absolute accuracy: ±2%
  • Repeatability: ±1%
  • Long term stability: ±0.5% per year
  • Price: $4 to $10

As you can see from the specs above, the DHT22 is a bit more accurate.

Where to buy?

You can check Maker Advisor Tools‘ page and find the best price for this modules:


Arduino with DHT11 Temperature and Humidity Sensor

You need the following components to make this circuit:


You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

Here’s how to connect the DHT11 to an Arduino:



  • VCC (3V to 5V)
  • Data OUT
  • Don’t connect
  • GND

Source code

Here’s the code you need for this project:

  1. Download the DHT11 library here
  2. Unzip the DHT library
  3. Rename the extracted folder and remove the “-“. Otherwise your Arduino IDE won’t recognize your library
  4. Install the DHT11 in your Arduino IDE
  5. Restart your Arduino IDE
  6. Go to Files / Examples / DHT_SENSOR_LIB / DHT Tester
  7. Upload the code


In this project the Arduino is measuring the temperature and humidity. Those two measures are being displayed in the serial monitor. Here’s what you should see in your Arduino IDE serial monitor.


I hope you found this guide useful.

Share this post with a friend that also likes electronics!

You can contact me by leaving a comment. If you like this post probably you might like my next ones, so please support me by subscribing my blog and my Facebook Page.

Thanks for reading,

-Rui Santos

Learn ESP32 with Arduino IDE

This our complete guide to program the ESP32 with Arduino IDE, including projects, tips, and tricks! The registrations are open, so SIGN UP NOW »

Leave a Comment:

Add Your Reply

⏰ Registrations are open ⏰
Sign up for "Learn ESP32 with Arduino IDE" Course