Hello everyone, in this article I will tell you what DHT11 and DHT22 are, their features, and detailed use. Come easy! 😁

What Are DHT11 and DHT22, and What Are They Used For?

DHT11 or DHT22 is a small sensor used to measure humidity and temperature in the environment. It is used to measure data and humidity in % of various heat units in Celsius, Fahrenheit, and kelvin values. DHT22 has better properties, is more stable, and is more expensive.

Features and Differences of DHT11 and DHT22

Operating voltage3 - 5V3 - 5V
Current mAh Max.2.5mAh2.5mAh
Humidity20-80% / 5%0-100% / 2-5%
Temperature0-50°C / ± 2°C-40 ile 80°C / ± 0.5°C
Measurement Speed1 Hz (1-Second Refresh)0.5 Hz (2-Second Refresh)
Physical dimensions15.5mm x 12mm x 5.5mm15.1mm x 25mm x 7.7mm
AdvantagesCheapMore Accurate Forecasting

For more detailed information, see DHT11 and DHT22 datasheets.

Let’s move on to its use without mentioning its internal structures. (If you like, I can also talk about its internal structure. Comments! 👇🏻 🫣 😁)

Use of DHT11 and DHT22

With DHT11 we will write a code about the use of DTH22 so that we can see the values on the serial monitor.

First, if you are using DHT11 or DHT22, download the library here. Download the latest version from the ‘Releases’ section. Now that our library has landed, let’s upload our library to Arduino. If you don’t know how to install it, learn here. 😊

Connection Diagram with Arduino

If you don't see the image, please let know in the comments!

Now that we’ve added our library, we can move on to coding!

Using DHT11 with Arduino

#include "DHT.h"  // DHT11 library

#define DHTPIN 2  // DHT11 data pin


void setup() {
  Serial.begin(9600); // serial communication is started
  dht.begin();        // dht is initialized

void loop() {
  delay(2000);        // Wait 2 seconds between each reading

  float humidity = dht.readHumidity();          // humidity information is obtained
  float temperature = dht.readTemperature();  // temperature information is received

  // read values are sent from serial port
  Serial.print("Humidity ");
  Serial.print(humidity  );
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.println(" *F ");

You can also check it out on my Github profile. 🫠

In this way, we can get the humidity and temperature values instantly! If you have any questions or problems you want to ask, you can tell them in the comments! Healthily! 😊