Please read the notice below / Molimo pročitajte napomenu ispod.


You are a beginner with Croduino. Or electronics? A specific module caught your eye, but you do not know how to use it? Do not worry, HUM is here for you! How to Use Module (HUM) is a blog tutorials series by e-radionica where you will find all you need in order to begin working with your favorite module. Tutorials include: technical characteristics, work principle, instructions on how to connect module with Croduino and the basic code. Everything else is left to your imagination.


DHT22 or AM2303 is a capacitive sensor for air humidity and air temperature. The sensor is of excellent quality, very precise, but a bit more expensive and slower (2 seconds). In addition to the measuring device, the modul consists of an 8-bit microcontroller and OTP memory which are used to calibrate each reading. Small dimensions, low power consumption and long distance data transfer (> 20m) make it applicable to many devices.


Voltage: 3.3 - 5.5V (recommended 5V)
Current: 300uA (average)
Measurement range: 0-100%RH; -40~80 °C
Accuracy: +-2%RH; +-0.5 °C
Long-term stability: +-0.5%RH/per year
Measurement time: 2s
Dimensions: 14x18x5.5mm

Diagrams below show the accuracy of readings depending on the measurements.

For more, check the datasheet.

How does the DHT22 work?

Croduino and DHT22 communicate via SDA (serial data) pin on the DHT and I/O pin on the Croduino, making the simplified single-bus (one-wire) communication. Due to its master/slave structure, SDA pin requires an external pull-up resistor. The resistor value depends on the length of the cable between the microcontroller and the sensor. It is recommended to use 5.1k resistors for 5V voltage, while the cables of >20m in length do not require a resistor. If you are using 3.3V voltage the cable length can be of up to 1m maximum.

This is how the measuring procedure looks like:

The microcontroller sends a start signal to the SDA pin of the DHT which turns from saving to running mode. The signal usually lasts for 1ms, after which the I/O microcontroller is set to input. DHT responds with 40bit data representing relative humidity and air temperature.

How to connect it to Croduino?

Untitled Sketch_bb

Arduino code

For readings off the DHT22 we will use a library which can be downloaded on the GitHub. If you are unsure of how to install a new library, follow this tutorial. The sample code, as always, can be found under File - Examples, after you have installed the library. Below is our version which provides humidity and air temperature readings, and feels like temperature.

/*                                                                           */
/*                                                                           */
/* (c) 2015 -      */
/*                                               */
/*                                                                           */
/*                                                                           */
/* DHT22 - HUM tutorial                                                      */

#include "DHT.h"

int pinDHT = A0;    // the pin to which we have connected SDA pin of the DHT
int tipDHT = DHT22; // you can also use DHT11 and DHT21 modules

// the first pin to +5V
// the second pin to wherever pinDHT is located 
// the third pin should remain empty
// the fourth pin to the gnd
// connect the 10k pull-up resistor between the second (SDA) pin and +5V

DHT dht(pinDHT, tipDHT);

void setup() {
  Serial.println("DHT test\n");

void loop() {
  // the interval between measurements must be of at least 2 seconds
  // also, before the first measurement, delay is necessary

  // read humidity
  float h = dht.readHumidity();
  // read air temperature in Celsius
  float t = dht.readTemperature();
  // for temperature reading in Fahrenheits, use:
  // float f = dht.readTemperature(true);

  // checking the heat index in Celsius
  float hic = dht.computeHeatIndex(t, h, false);
  // for checking in Fahrenheits, use:
  // float hif = dht.computeHeatIndex(f, h);
  // verification of measurement performance..
  if (isnan(h) || isnan(t)) {
    Serial.println("Neuspješno čitanje s DHT-a");
  // if everything is fine, print out the readings:
  Serial.print("Relativna vlaga zraka: ");
  Serial.print("Temperatura: ");
  Serial.print("*C ");
  Serial.print("Feels like: ");
Leave a Reply