0% found this document useful (0 votes)
148 views7 pages

DHT11 Datasheet

The document discusses using DHT11 and DHT22 sensors to measure temperature and humidity with an Arduino board. The DHT22 sensor has better accuracy for both temperature (±0.5°C vs ±2°C) and humidity (2-5% vs 5%) compared to the DHT11, but the DHT11 has a faster sampling rate of 1 Hz vs 0.5 Hz for the DHT22. Both sensors operate from 3-5V and connect to the Arduino with power, ground, data, and an unused pin. The document provides code examples to read temperature and humidity values and display them on the serial monitor or LCD screen.

Uploaded by

reni lee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
148 views7 pages

DHT11 Datasheet

The document discusses using DHT11 and DHT22 sensors to measure temperature and humidity with an Arduino board. The DHT22 sensor has better accuracy for both temperature (±0.5°C vs ±2°C) and humidity (2-5% vs 5%) compared to the DHT11, but the DHT11 has a faster sampling rate of 1 Hz vs 0.5 Hz for the DHT22. Both sensors operate from 3-5V and connect to the Arduino with power, ground, data, and an unused pin. The document provides code examples to read temperature and humidity values and display them on the serial monitor or LCD screen.

Uploaded by

reni lee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

DHT11 & DHT22 Sensors Temperature and

Humidity Tutorial using Arduino


Dejan
Arduino Tutorials
16

In this Arduino Tutorial we will learn how to use the DHT11 or the DHT22 sensor for
measuring temperature and humidity with the Arduino board. You can watch the following
video or read the written tutorial below for more details.

Overview

These sensors are very popular for electronics hobbyists because there are very cheap but still
providing great performance. Here are the main specifications and differences between these
two sensors:

The DHT22 is the more expensive version which obviously has better specifications. Its
temperature measuring range is from -40 to +125 degrees Celsius with +-0.5 degrees
accuracy, while the DHT11 temperature range is from 0 to 50 degrees Celsius with +-2
degrees accuracy. Also the DHT22 sensor has better humidity measuring range, from 0 to
100% with 2-5% accuracy, while the DHT11 humidity range is from 20 to 80% with 5%
accuracy.
There are two specification where the DHT11 is better than the DHT22. That’s the sampling
rate which for the DHT11 is 1Hz or one reading every second, while the DHT22 sampling
rate is 0,5Hz or one reading every two seconds and also the DHT11 has smaller body size.
The operating voltage of both sensors is from 3 to 5 volts, while the max current used when
measuring is 2.5mA.

You can get these components from any of the sites below:

 DHT11 Sensor…………………………….. Amazon / Banggood


 DHT22 Sensor……………………………. Amazon / Banggood
 Arduino Board …………………………… Amazon / Banggood
 Breadboard and Jump Wires ……… Amazon / Banggood

*Please note: These are affiliate links. I may make a commission if you buy the components
through these links. I would appreciate your support in this way!

DHT11 / DHT22 Working Principle

Ok now let’s see how these sensors actually work. They consist of a humidity sensing
component, a NTC temperature sensor (or thermistor) and an IC on the back side of the
sensor.

For measuring humidity they use the humidity sensing component which has two electrodes
with moisture holding substrate between them. So as the humidity changes, the conductivity
of the substrate changes or the resistance between these electrodes changes. This change in
resistance is measured and processed by the IC which makes it ready to be read by a
microcontroller.
On the other hand, for measuring temperature these sensors use a NTC temperature sensor or
a thermistor.

A thermistor is actually a variable resistor that changes its resistance with change of the
temperature. These sensors are made by sintering of semiconductive materials such as
ceramics or polymers in order to provide larger changes in the resistance with just small
changes in temperature. The term “NTC” means “Negative Temperature Coefficient”, which
means that the resistance decreases with increase of the temperature.

Circuit Schematics

The DHTxx sensors have four pins, VCC, GND, data pin and a not connected pin which has
no usage. A pull-up resistor from 5K to 10K Ohms is required to keep the data line high and
in order to enable the communication between the sensor and the Arduino Board. There are
some versions of these sensors that come with a breakout boards with built-in pull-up resistor
and they have just 3 pins.
The DHTXX sensors have their own single wire protocol used for transferring the data. This
protocol requires precise timing and the timing diagrams for getting the data from the sensors
can be found from the datasheets of the sensors. However, we don’t have to worry much
about these timing diagrams because we will use the DHT library which takes care of
everything.

Source Code

First we need to included the DHT library which can be found from the Arduino official
website, then define the pin number to which our sensor is connected and create a DHT
object. In the setup section we need to initiate the serial communication because we will use
the serial monitor to print the results. Using the read22() function we will read the data from
the sensor and put the values of the temperature and the humidity into the t and h variables. If
you use the DHT11 sensor you will need to you the read11() function. At the end we will
print the temperature and the humidity values on the serial monitor.

1. /* DHT11/ DHT22 Sensor Temperature and Humidity Tutorial


2. * Program made by Dejan Nedelkovski,
3. * www.HowToMechatronics.com
4. */
5. /*
6. * You can find the DHT Library from Arduino official website
7. * https://playground.arduino.cc/Main/DHTLib
8. */
9.
10. #include <dht.h>
11.
12. #define dataPin 8 // Defines pin number to which the sensor is connected
13. dht DHT; // Creats a DHT object
14.
15. void setup() {
16. Serial.begin(9600);
17. }
18. void loop() {
19. int readData = DHT.read22(dataPin); // Reads the data from the sensor
20. float t = DHT.temperature; // Gets the values of the temperature
21. float h = DHT.humidity; // Gets the values of the humidity
22.
23. // Printing the results on the serial monitor
24. Serial.print("Temperature = ");
25. Serial.print(t);
26. Serial.print(" *C ");
27. Serial.print(" Humidity = ");
28. Serial.print(h);
29. Serial.println(" % ");
30.
31. delay(2000); // Delays 2 secods, as the DHT22 sampling rate is 0.5Hz
32. }

After we will upload this code to the Arduino board, the temperature and humidity results
from the sensor can be seen on the Serial monitor.

I also made an example where I display the results on a LCD. Here’s the source code of that
example:

1. /* DHT11/ DHT22 Sensor Temperature and Humidity Tutorial


2. * Program made by Dejan Nedelkovski,
3. * www.HowToMechatronics.com
4. */
5. /*
6. * You can find the DHT Library from Arduino official website
7. * https://playground.arduino.cc/Main/DHTLib
8. */
9.
10. #include <LiquidCrystal.h> // includes the LiquidCrystal Library
11. #include <dht.h>
12.
13.
14. #define dataPin 8
15. LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LCD object. Parameters: (rs, enable,
d4, d5, d6, d7)
16. dht DHT;
17.
18. void setup() {
19. lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the
dimensions (width and height) of the display
20. }
21.
22. void loop() {
23. int readData = DHT.read22(dataPin);
24. float t = DHT.temperature;
25. float h = DHT.humidity;
26. lcd.setCursor(0,0); // Sets the location at which subsequent text written to the LCD
will be displayed
27. lcd.print("Temp.: "); // Prints string "Temp." on the LCD
28. lcd.print(t); // Prints the temperature value from the sensor
29. lcd.print(" C");
30. lcd.setCursor(0,1);
31. lcd.print("Humi.: ");
32. lcd.print(h);
33. lcd.print(" %");
34. delay(2000);
35. }

DHT11 & DHT22 Sensor Suhu dan Kelembaban Tutorial menggunakan Arduino
Dejan
Tutorial Arduino
16
Dalam Tutorial Arduino ini kita akan belajar bagaimana menggunakan DHT11 atau sensor DHT22
untuk mengukur suhu dan kelembaban dengan papan Arduino. Anda dapat menonton video berikut
atau membaca tutorial tertulis di bawah ini untuk lebih jelasnya.
Ikhtisar
________________________________________
Sensor ini sangat populer untuk penggemar elektronik karena harganya sangat murah tetapi tetap
memberikan kinerja yang luar biasa. Berikut spesifikasi dan perbedaan utama antara kedua sensor
ini:
DHT22 adalah versi yang lebih mahal yang jelas memiliki spesifikasi yang lebih baik. Rentang
pengukuran suhu dari -40 hingga +125 derajat Celcius dengan akurasi + -0,5 derajat, sedangkan
rentang temperatur DHT11 adalah 0 hingga 50 derajat Celsius dengan + -2 derajat akurasi. Juga
sensor DHT22 memiliki rentang pengukuran kelembaban yang lebih baik, dari 0 hingga 100% dengan
akurasi 2-5%, sementara rentang kelembaban DHT11 adalah 20 hingga 80% dengan akurasi 5%.

Ada dua spesifikasi di mana DHT11 lebih baik daripada DHT22. Itu adalah laju pengambilan sampel
untuk DHT11 adalah 1 Hz atau satu bacaan setiap detik, sedangkan tingkat sampling DHT22 adalah
0,5 Hz atau satu bacaan setiap dua detik dan juga DHT11 memiliki ukuran tubuh yang lebih kecil.
Tegangan operasi kedua sensor adalah 3 hingga 5 volt, sedangkan arus maksimal yang digunakan
saat mengukur adalah 2,5mA.
Anda bisa mendapatkan komponen-komponen ini dari salah satu situs di bawah ini:
• Sensor DHT11 …………………………… .. Amazon / Banggood
• Sensor DHT22 ……………………………. Amazon / Banggood
• Arduino Board …………………………… Amazon / Banggood
• Breadboard dan Jump Wires ……… Amazon / Banggood
* Harap dicatat: Ini adalah tautan afiliasi. Saya dapat membuat komisi jika Anda membeli komponen
melalui tautan ini. Saya akan menghargai dukungan Anda dengan cara ini!
DHT11 / DHT22 Prinsip Kerja
________________________________________
Ok sekarang mari kita lihat bagaimana sensor ini bekerja. Mereka terdiri dari komponen
penginderaan kelembaban, sensor suhu NTC (atau termistor) dan IC di sisi belakang sensor.

Untuk mengukur kelembaban mereka menggunakan komponen penginderaan kelembaban yang


memiliki dua elektroda dengan substrat menahan kelembaban di antara mereka. Jadi ketika
kelembaban berubah, konduktivitas substrat berubah atau resistensi antara elektroda-elektroda ini
berubah. Perubahan resistansi ini diukur dan diproses oleh IC yang membuatnya siap dibaca oleh
mikrokontroler.

Di sisi lain, untuk mengukur suhu, sensor ini menggunakan sensor suhu NTC atau termistor.
Termistor sebenarnya adalah resistor variabel yang mengubah ketahanannya dengan perubahan
suhu. Sensor-sensor ini dibuat dengan sintering bahan semikonduktif seperti keramik atau polimer
untuk memberikan perubahan yang lebih besar pada hambatan hanya dengan perubahan suhu yang
kecil. Istilah "NTC" berarti "Koefisien Suhu Negatif", yang berarti bahwa resistensi menurun dengan
peningkatan suhu.

Skema Sirkuit
________________________________________
Sensor DHTxx memiliki empat pin, VCC, GND, pin data dan pin yang tidak terhubung yang tidak
memiliki penggunaan. Sebuah resistor pull-up dari 5K ke 10K Ohms diperlukan untuk menjaga jalur
data tetap tinggi dan untuk memungkinkan komunikasi antara sensor dan Arduino Board. Ada
beberapa versi dari sensor ini yang datang dengan papan breakout dengan resistor pull-up built-in
dan mereka hanya memiliki 3 pin.

Sensor DHTXX memiliki protokol kawat tunggal mereka sendiri yang digunakan untuk mentransfer
data. Protokol ini membutuhkan pengaturan waktu yang tepat dan diagram waktu untuk
mendapatkan data dari sensor dapat ditemukan dari lembar data sensor. Namun, kami tidak perlu
khawatir tentang diagram waktu ini karena kami akan menggunakan perpustakaan DHT yang
menangani semuanya.
Kode sumber
________________________________________
Pertama kita perlu menyertakan perpustakaan DHT yang dapat ditemukan dari situs web resmi
Arduino, kemudian tentukan nomor pin yang terhubung dengan sensor kita dan buat objek DHT. Di
bagian pengaturan kita perlu memulai komunikasi serial karena kita akan menggunakan monitor
serial untuk mencetak hasilnya. Menggunakan fungsi read22 () kita akan membaca data dari sensor
dan meletakkan nilai-nilai suhu dan kelembaban ke dalam t dan h variabel. Jika Anda menggunakan
sensor DHT11, Anda akan membutuhkan fungsi read11 (). Pada akhirnya kami akan mencetak suhu
dan nilai kelembaban pada monitor serial.

You might also like