DHT22 - the precision temperature and humidity sensor

DHT22 sensor

Already in a previous article we present the DHT11, another of the temperature and humidity sensors that you have at your disposal. But in this new article we will tell you everything you need to know about DHT22. Usually, to the naked eye, the only difference between the DHT11 and the DHT22 is that the former comes in a blue casing and the latter is white. In fact, both are brothers of the same family of sensors.

El DHT11 is the little brother, that is to say, it has some shortcomings or benefits of less compared to DHT22, and therefore a higher price. The DHT11 can be used for projects where you do not require high measurement precision, while if you want something more precise you should choose the DHT22. The 22 is not really high precision either, but it does have more than acceptable performance for most DIY maker projects.

What is DHT22?

DHT22 module

El DHT22 is a temperature and humidity sensor with features that are very close to high precision. You can easily find it in specialized stores or department stores, where you can buy it for a few euros. That allows you not to have to depend on a temperature sensor and a humidity sensor separately, but to have everything integrated in the same device.

You can find it loose or in modules specially designed for Arduinoi.e. the DHT22 mounted on a ready-to-use PCB board, without having to add pull-up resistors, etc. So far everything looks a lot like DHT11. And you will also have high reliability and stability in measurements due to the calibrated digital signal it uses.

Pinout, features and datasheet

DHT11 pinout

In the image above you can see a comparison of the DHT22 and DHT11 pinout, and as you can see they are identical in terms of sideburns. Therefore, its assembly would be exactly the same, and the best thing is, you could replace the DHT11 with a DHT22 at any time, and vice versa, in your project without making too many changes.

Remember that they have 3 pins that you must use: GND, Vcc and Data. Pin # 3 is not used and in modules it is bypassed, that is, you will only see three pins. If you want to see more details about the product you have purchased, you can search the datasheets of the specific model and manufacturer to obtain all the complete information. Although most values ​​may look the same to you, there could be some slight variation from one to the other. Its most important technical characteristics are:

  • 3,3v to 6v power supply
  • 2,5mA current consumption
  • Digital output signal
  • Temperature range from -40ºC to 125ºC
  • Accuracy to measure temperature at 25ºC of 0.5ºC variation
  • The resolution to measure temperature is 8-bit, 0,1ºC
  • Humidity can measure from 0% RH to 100% RH
  • Accurately humidity 2-5% RH for temperatures between 0-50ºC
  • The resolution is 0,1% RH, it cannot pick up variations below that
  • Sampling rate of 2 samples per second: 2Hz
  • Sparkfun Datasheet

If you have read our manual on DHT11 you will know that transmits in digital for its Data pin, therefore, another advantage for these sensors. It will not be necessary to generate code in the Arduino IDE to go from analog to values ​​understandable to the human, but the digital signal can be directly processed to pass it to degrees or percentage of relative humidity.

In part, this is also why it is so accurate, since with the 40-bit frame transmitting, the precision is higher. It even includes a few parity bits to detect signal failures. You don't have that with an analog signal, apart from the fact that the analog is very sensitive to voltage variations ...

Integration with Arduino

DHT22 connected to board Arduino UNO

As with DHT11, installing the DHT22 with Arduino is quite easy. Remember that if you use it alone, without it being mounted on a module and the sensor is far away (or if you use a lower voltage to power it), you will have to use a pull-up resistor that makes a bridge between the Vcc pin and the Data pin. But if you use the module, you can save it and connect it directly as it appears in the image above ... Also, remember that in the module the NC pin that is not used will not be present, so it will be even easier for you not to get confused.

You just need to connect GND and Vcc to the proper connections of your Arduino board, that is, to those marked as GND and 5v in this case. And for the Data pin, you can connect it to any of the Arduino's digital inputs, in our case we have done it in 7. If you use another, remember to rectify the code so that it works with your way of connecting the components (it seems obvious but it is a very common mistake when copying and pasting the codes in Arduino IDE).

Code in Arduino IDE

Now that you have it connected, let's see a simple code example for Arduino IDE. . Remember that we have a beginner's guide that starts with Arduino in PDF that you can download free from here and it can help you. Also, if you have read our article on DHT11, remember that there was a library to use the DHTxx sensorstherefore, the same one that was used for DHT11 can be used for DHT22.

Once you have installed the library and everything is ready, now is when you must enter the code to program the Arduino microcontroller to make your project work. A basic example would be:

#include "DHT.h"
// Ejemplo sencillo de uso para el DHT22
const int DHTPin = 7;     
void setup() {
   Serial.println("Test DHT22");
void loop() {
   // Tiempo de espera entre tomas de mediciones de 2 segundos.
   // Lee temperatura y humedad durante unos 250ms
   float h = dht.readHumidity();
   float t = dht.readTemperature();
   if (isnan(h) || isnan(t)) {
      Serial.println("Fallo en la lectura");
   Serial.print("Humedad relativa: ");
   Serial.print(" %\t");
   Serial.print("Temperatura: ");
   Serial.print(" *C ");

I hope that our guides on DHTxx have served as your guide, although in general the projects that are usually done are somewhat more complex, but these codes to see how the sensor works are quite indicative and then modify the code and add whatever you want ...

The content of the article adheres to our principles of editorial ethics. To report an error click here!.

A comment, leave yours

Leave a Comment

Your email address will not be published. Required fields are marked with *



  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   rogger said

    good information posted. Only one detail could include the publication date. sometimes we need it as a reference for works written with standards. Thank you.