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”.

Schematic

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

tutorial dht arduino

Library

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

Program

Following is an example program showing temperature data.

#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11   // DHT 11
DHT dht(DHTPIN, DHTTYPE);

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

  dht.begin();
}

void loop() {
  delay(2000);
  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!"));
    return;
  }

  // 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(h);
  Serial.print(F("%  Temperature: "));
  Serial.print(t);
  Serial.print(F("°C "));
  Serial.print(f);
  Serial.print(F("°F  Heat index: "));
  Serial.print(hic);
  Serial.print(F("°C "));
  Serial.print(hif);
  Serial.println(F("°F"));
}

Result

The results are as follows:

Read other articles  How To Use Nokia LCD 5110 With Arduino

DHT11 datasheet english

Leave a Reply

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