tutorial dht arduino

How to Use DHT11 Sensor With Arduino Uno

Posted on

How to Use DHT11 Sensor – DHT11 is a temperature and humidity sensor. This sensor has two sensors inside, capacitive humidity sensor and thermistor. Although including cheap and slow sensors in sending data, this sensor is suitable for beginners in making a detector for temperature and humidity. This sensor has the maximum specifications as follows:

  • Range of Temperature measurement is 0 – 50 ℃
  • Range of humidity measurements is 20 – 90% RH
  • Accuracy of temperature reading is ± 2 ℃
  • Accuracy of humidity reading is ± 5 %
  • The Working voltage is 3.3 – 5.5V

The detailed specifications of the Arduino DHT11 sensor that I quoted from his datasheet:

DHT11 datasheet english

Download DHT11 Datasheet

The principle of working DHT11

For sending and receiving data between Arduino, this sensor uses a serial interface (single wayer two-way). This means that this sensor uses only one pin for sending and receiving data. In the datasheet, this sensor takes 4ms at a time during communication. Data packets sent to Arduino as much as 40bit. The data format sent by DHT11 to Arduino is as follows: “8-bit integral RH data + 8-bit decimal RH data + 8-bit integral T data + 8-bit decimal T data+ 8-bit condition data”.


To be able to use the DHT11 sensor on Arduino, please follow the following schematic.

tutorial dht arduino


To facilitate programming, this library of sensors is available which we will use using Arduino. There are two ways to get this library. First from the library manager in Arduino IDE, seconds is enter manually in Folder. The library that I attached is taken from adafruit industries. Please download the following library and add it into your Arduino IDE:

Download DHT Library


Following is an example program showing temperature data.

#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11   // DHT 11

void setup() {
  Serial.println(F("DHTxx test!"));


void loop() {
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println(F("Failed to read from DHT sensor!"));

  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print(F("Humidity: "));
  Serial.print(F("%  Temperature: "));
  Serial.print(F("°C "));
  Serial.print(F("°F  Heat index: "));
  Serial.print(F("°C "));


The results are as follows:

Read other articles  How To Program ATTiny13 / ATTiny13A using Arduino

DHT11 datasheet english

Leave a Reply

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