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

MicroPython Programming with ESP32/ESP8266 eBook

Learn how to program the ESP boards with MicroPython, including projects, tips, and tricks! The registrations are open for a limited time, so SIGN UP NOW »

Recommended Resources

Home Automation using ESP8266 »
Build IoT projects and home automation gadgets with the ESP8266 Wi-Fi module.

Build a Home Automation System »
Learn how to build a automation system using open-source hardware and software from scratch.

Arduino Step-by-Step Projects »
Build 25 cool Arduino projects with our course even with no prior experience!

Leave a Comment:

Add Your Reply

⏰ Registrations are open for "MicroPython Programming with ESP32 and ESP8266" eBook