What is DHT11 temperature and humidity sensor ?
Application in practice like?
What sensor do you use?
These are questions that newcomers want to know.
Through today's article we learn together offline.
DHT11 temperature and humidity sensor
DHT11 humidity and temperature sensors are very popular sensors because they are cheap and easy to get data through the standard 1-wire interface.
The standard of 1 wire communication is to use 1 digital pin to transfer data.
The signal preprocessor is built into the sensor so you can read the data accurately without any calculations.
DHT11 temperature and humidity sensor module
Sensor specifications:
- Operating voltage: 3V - 5V (DC)
- Operating humidity range: 20% - 90% RH, error of ± 5% RH
- Operating temperature range: 0 ° C ~ 50 ° C, tolerance ± 2 ° C
- Maximum transmission distance: 20m
You download and install the library to support using DHT11: Here
Connection diagram
Arduino Uno | DHT11 temperature and humidity sensor |
5V | VCC |
GND | GND |
D4 | DATA |
The necessary components for the project:
- Arduino UNO: >> View product here.
- DHT11 temperature, humidity sensor: >> View product here.
Code
#include "DHT.h"
const int DHTPIN = 4 ;
const int DHTTYPE = DHT11 ;
DHT dht ( DHTPIN , DHTTYPE ) ;
void setup ( ) {
Serial . begin ( 9600 ) ;
dht . begin ( ) ;
}
void loop ( ) {
float h = dht . readHumidity ( ) ;
float t = dht . readTemperature ( ) ;
Serial . print ( "Due:" ) ;
Serial . println ( t ) ;
Serial . print ( "Do am:" ) ;
Serial . println ( h ) ;
Serial . println ( ) ;
delay ( 1000 ) ;
}
Explain the code
Declare connection pin for DHT sensor here I use pin D4 on Arduino Uno.
const int DHTPIN = 4 ; const int DHTTYPE = DHT11 ;
DHT.h library is declared to be used for 2 types of sensors: DHT11 and DHT22.
In our article, we introduce the DHT11 temperature and humidity sensor , so we need to declare that DHTTYPE is DHT11.
float h = dht . readHumidity ( ) ; // Read temperature value from float sensor t = dht . readTemperature ( ) ; // Read humidity value from the sensor
Above are two variables that read the temperature and humidity values.
Serial . print ( "Due:" ) ; Serial . println ( t ) ; Serial . print ( "Do am:" ) ; Serial . println ( h ) ;
Print temperature and humidity values on the screen (Serial Monitor).
- To understand more about the functions Serial.print () and Serial.println (), please see the article here: See now.
We proceed to Upload the program and turn on Serial Monitor to see the results.