blog

DHT11 temperature and humidity detectionsensor

DHT11(1)

If you’re interested in temperature and humidity detection, we recommend the DHT11 sensor to you.

What does DHT stand for in sensors?

In sensors, DHT stands for temperature and humidity. DHT sensors can be connected to many microcontrollers (such as Arduino, ESP32, STM32, etc.) to achieve real-time detection of temperature and humidity at a low cost (with a delay).

What is DHT11 sensor?

 The DHT11 is a very commonly used temperature and humidity sensor nowadays. It consists of a capacitive humidity measurement component, an NTC temperature measurement component (thermistor), and is equipped with an 8-bit microcontroller to output temperature and humidity in the form of serial data.

What is the function of DHT11?

 The DHT11 includes a capacitive humidity measurement component and an NTC temperature measurement component, and measurement can be done through the capacitive humidity measurement component. The moisture in the air causes changes in capacitance, which is used to determine relative humidity. Temperature measurement is based on the thermal effect of the thermistor (the resistance value changes linearly within a specific temperature range, and when the surrounding temperature changes, the resistance changes accordingly), which enables temperature measurement. In addition, the DHT11 sensor can convert the analog signals measured by the temperature and humidity sensor into digital signals used by the MCU through an 8-bit microcontroller for output.

What are the application scenarios for DHT11? 

The DHT11 sensor is often used for measuring environmental temperature and humidity. For example, in the field of smart home, the DHT11 can measure indoor temperature and humidity, convert the data into digital signals, and then transmit them to the control system. The control system can control devices like air conditioners to adjust indoor temperature and humidity according to set values, so as to maintain a comfortable indoor environment. For instance, if the temperature is too high in summer, the air conditioner will be automatically turned on for cooling; if the humidity is too high on rainy days, the dehumidifier will be turned on.

Here is a video to show you about DHT11 module to make a simple smart home

DHT11 Specification Parameter Table

A detailed data sheet can be found below

How to connect DHT11 with Arduino?

We provide you with an example of connecting DHT11 to Arduino.
DHT11 connects to Arduino and oled screen
DHT11 connects to Arduino and oled screen
DHT11 connecting Arduino and oled display diagram

DHT11 connecting Arduino and oled display diagram

DHT11 sensor library for Arduino

Arduino as a platform developed for beginners, it has many sensor driver libraries integrated inside, and of course, DHT11 is included. You just need to search for and install the library “DHT sensor library”. Note that this library requires another library to run, so you can’t use it by installing only this one. But you don’t have to worry about it, as the official Arduino has thought of this. When installing, you just need to click “Install all” and then you can use it with confidence.

Arduino Display Diagram1

Arduino Display Diagram1

About the LED screen in the Arduino display is also similar, you need to search and install “Adafruit SSD1306: 2.3.0 can be, also need to be installed when clicking on the ”Install all” on it!

Arduino Display Diagram2
Arduino Display Diagram2

Program Code Example

After installing the library, we provide you with sample code to display temperature and humidity on the OLED screen. You can also modify the code accordingly to achieve other functions you need.

				
					#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>//OLED library
#include <DHT.h>//DHT11 library
DHT dht(8, DHT11);//Set the communication pins and models between DHT11 and Arduino
Adafruit_SSD1306 display(128,64, &Wire, -1);//Set the screen size of OLED
void setup()
{
  pinMode(7,OUTPUT);//Motor signal output
  dht.begin();//Dht11 initialization
  Serial.begin(9600);//Configure serial port baud rate
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);//Initialize OLED and set IIC communication address
}
void loop()
{  
  float h = dht.readHumidity();//Read Temperature
  float t = dht.readTemperature();//Read humidity
  display.clearDisplay();//Clear screen
  display.setTextColor(WHITE);//Setting text color, monochrome OLED is invalid, but must have
  display.setTextSize(2);//Set text size
  if(t>=26)//If the temperature is greater than 26
  {
    display.setCursor(0,40);
    display.print("Warning!");
    digitalWrite(7,HIGH);//Start the fan
    }
  else
  {
    display.setCursor(0,40);
    display.print("Safe");
    digitalWrite(7,LOW);//stop the fan
    }
  display.setCursor(0, 0);//Set the starting X and Y axes of the text
  display.print("Temp:");
  display.print(t,1);//One decimal place
  display.print("C");
  display.setCursor(0, 20);
  display.print("Humi:");
  display.print(h,1);
  display.print("%");
  display.display();//Execute Display
  delay(1000);//Reduce the read frequency of DHT11 to prevent read failures
}
				
			

How does DHT11 communicate?

 The DHT11 communicates through a single serial communication line, which is essentially digital communication. It represents 1 and 0 according to the length of time the high level is sent. Different from ordinary serial communication, serial communication sends high level within a fixed time range to represent 1 and low level to represent 0, and it is necessary to set the communication frequency of both parties in advance, that is the baud rate. Therefore, DHT11 communication is a special communication method,it is necessary to write a separate communication protocol through the internal timer, but for Arduino, there are special library functions provided internally for communication with DHT11, and data can be read directly with just two simple functions.

DHT11 PINS

The separate four-pin part includesVCC(1),EN(2),DATA(3), and GND(4) 。

EN can be connected to VCC on the normal case. Therefore, the DHT11s on sale all directly connect the EN to the VCC using a circuit board instead of separately leading it out, which simplifies the user’s usage process. Just plug it in and it can be used. If you need customization or control the enable pin, you can also remove it and connect the circuit separately.
DHT11 Dimension Drawing
DHT11 Dimension Drawing

Comparison of DHT11 and DHT22 and DS18B20 parameters

Functionally speaking, DHT11 and DHT22 can achieve synchronous monitoring of temperature and humidity, while DS18B20 can only measure temperature. However, in terms of accuracy, if you only need to measure temperature, DS18B20 has higher accuracy, and the temperature and humidity sensor DHT22 also has higher accuracy than DHT11, which corresponds to its higher price. If you don’t have high requirements for accuracy, in terms of cost performance, we recommend DHT11 to you. If you need to measure high-precision temperature and humidity, you can also choose our DHT22 sensor.

DHT11 Sensor Datasheet

Here we provide you with a detailed data sheet of the DHT11 Sensor for reference.

FAQ

How to tell if a humidity sensor is working?

First, use the microcontroller to send a normal communication trigger timing signal to see if there is data returned, and then check whether the returned data matches the check code.

Does DHT11 need a resistor?

Because the internal signal driving capability of DHT11 is very weak, if the signal receiver is an open-drain input, a pull-up resistor must be provided, otherwise the level rise speed will be too slow and the signal will be wrong. However, most MCU ports are equipped with pull-up resistors internally, so theoretically you don’t have to worry about this. Of course, you can also add a 4.7K pull-up resistor as a safeguard.

Does DHT11 need calibration?

No, the DHT11 has been tested before leaving the factory, and unqualified products will be returned for re- debugging.

Leave a Reply

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