Blog
DHT11 temperature and humidity detectionsensor
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
| DHT11 Sensor | |
| Maximum operating current | 2.5mA(max) |
| Operating voltage | Minimum operating voltage (min): 3V Maximum operating voltage (max): 5V |
| Measurable humidity range | 20%—95%(RH) |
| Measurable temperature range | 0°C—50°C |
| Sampling rate | <=1Hz |
| Error range | Humidity error range: ±5% RH Temperature error range: ±2% °C |
A detailed data sheet can be found below
How to connect DHT11 with Arduino?
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
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!
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
#include //OLED library
#include //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?
DHT11 PINS
The separate four-pin part includesVCC(1),EN(2),DATA(3), and GND(4) 。
Comparison of DHT11 and DHT22 and DS18B20 parameters
| Item | DHT11 | DHT22 | DS18B20 |
|---|---|---|---|
| Price | $1.5 | $3 | $1.2 |
| Function | Temperature and humidity measurement | Temperature and humidity measurement | Temperature measurement |
| Accuracy | Temperature: 2% Humidity: 5% |
1% 2% |
0.5% |
| Maximum reading frequency | <=1Hz | <=0.5Hz | <=1.35Hz |
| Volume | 12.5x6x16 | 12.5x6x16 | 3.3×4.3×4.3 |
| Measurement range | Temperature: 0-50°C Humidity: 20%-90% |
-40-80°C 0-99.9% |
-55 to +125 |
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
FAQ
How to tell if a humidity sensor is working?
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.