Hello everyone, in this article I will tell you what DHT11 and DHT22 are, their features, and detailed use. Come easy! ๐
What Are DHT11 and DHT22, and What Are They Used For?
DHT11 or DHT22 is a small sensor used to measure humidity and temperature in the environment. It is used to measure data and humidity in % of various heat units in Celsius, Fahrenheit, and kelvin values. DHT22 has better properties, is more stable, and is more expensive.
Features and Differences of DHT11 and DHT22
DHT11 | DHT22 | |
---|---|---|
Operating voltage | 3 - 5V | 3 - 5V |
Current mAh Max. | 2.5mAh | 2.5mAh |
Humidity | 20-80% / 5% | 0-100% / 2-5% |
Temperature | 0-50°C / ± 2°C | -40 ile 80°C / ± 0.5°C |
Measurement Speed | 1 Hz (~1 Second Refresh) | 0.5 Hz (~2 Second Refresh) |
Physical dimensions | 15.5mm x 12mm x 5.5mm | 15.1mm x 25mm x 7.7mm |
Advantages | Cheap | More Accurate Forecasting |
For more detailed information, see DHT11 and DHT22 datasheets.
Let’s move on to its use without mentioning its internal structures. (If you like, I can also talk about its internal structure. Comments! ๐๐ป ๐ซฃ ๐)
Use of DHT11 and DHT22
With DHT11 we will write a code about the use of DTH22 so that we can see the values on the serial monitor.
First, if you are using DHT11 or DHT22, download the library here. Download the latest version from the ‘Releases’ section. Now that our library has landed, let’s upload our library to Arduino. If you don’t know how to install it, learn here. ๐
Connection Diagram with Arduino
Now that we’ve added our library, we can move on to coding!
Using DHT11 with Arduino
#include "DHT.h" // DHT11 library
#define DHTPIN 2 // DHT11 data pin
DHT dht(DHTPIN, DHT11);
void setup() {
Serial.begin(9600); // serial communication is started
dht.begin(); // dht is initialized
}
void loop() {
delay(2000); // Wait 2 seconds between each reading
float humidity = dht.readHumidity(); // humidity information is obtained
float temperature = dht.readTemperature(); // temperature information is received
// read values are sent from serial port
Serial.print("Humidity ");
Serial.print(humidity );
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" *F ");
}
You can also check it out on my Github profile. ๐ซ
In this way, we can get the humidity and temperature values instantly! If you have any questions or problems you want to ask, you can tell them in the comments! Healthily! ๐