Compatibility
The library has been tested and confirmed to work on the following boards:
- Arduino Uno R3 (ATmega328P – AVR architecture)
-
NodeMCU ESP32S v1.1
ESP-WROOM-32
(Tensilica Xtensa LX6 – xtensa architecture) -
NodeMCU ESP8266 v1.0
ESP8266MOD
(Tensilica Xtensa LX106 – xtensa architecture)
Given the vast number of boards and architectures available, it’s a challenge for a solo developer to test on all. Community contributions in terms of compatibility testing are highly encouraged.
Contribute by Testing
If you’ve successfully used this library on a board not listed above, please consider contributing by letting me know. This will help the community to have a broader understanding of the library’s compatibility.
-
Fork the
repository
. - Update the README with the board you’ve tested.
- Create a pull request with your changes.
Your contribution will be greatly appreciated, and it will benefit the entire Arduino community.
Introduction
This Arduino library is designed for the DHT11 temperature and humidity sensor. It simplifies the process of reading temperature and humidity data, making it easy to integrate the DHT11 sensor into your Arduino projects.
Author:
Dhruba Saha
Version:
2.1.0
License:
MIT
Code mẫu
#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(“Nhiet do: “); Serial.println(t); Serial.print(“Do am: “); Serial.println(h); Serial.println(); delay(1000); }
Giải thích code
Khai báo chân kết nối cho cảm biến DHT ở đây mình dùng chân D4 trên Arduino Uno.
const int DHTPIN = 4; const int DHTTYPE = DHT11;
Thư viện DHT.h được khai báo sử dụng cho 2 loại cảm biến là DHT11 và DHT22.
Trong bài viết mình giới thiệu cảm biến nhiệt độ, độ ẩm DHT11, nên chúng ta cần phải khai báo là DHTTYPE là DHT11.
float h = dht.readHumidity(); // Đọc giá trị nhiệt độ từ cảm biến float t = dht.readTemperature(); // Đọc giá trị độ ẩm từ cảm biến
Ở trên là hai biến đọc giá trị nhiệt độ và độ ẩm.
Serial.print(“Nhiet do: “); Serial.println(t); Serial.print(“Do am: “); Serial.println(h);
In giá trị nhiệt độ, độ ẩm lên màn hình (Serial Monitor).
- Để hiểu hơn về hàm Serial.print() và Serial.println() các bạn xem bài viết ở đây nhé:Xem ngay.
Chúng ta tiến hành Upload chương trình và bật Serial Monitor lên để xem kết quả nhé.
Description
An Arduino library for the DHT series of low-cost temperature/humidity sensors.
You can find DHT tutorials
here
.
Dependencies
Contributing
Contributions are welcome! Not only you’ll encourage the development of the library, but you’ll also learn how to best use the library and probably some C++ too
Please read our
Code of Conduct
before contributing to help this project stay welcoming.
Installation
Arduino IDE Library Manager
- Open the Arduino IDE.
-
Go to
Sketch
>
Include Library
>
Manage Libraries...
. - In the Library Manager, enter “DHT11” into the search box.
- Find the DHT11 library in the list and install it.
Installing Manually from GitHub
- Download the latest release of the library from this GitHub repository as a ZIP file.
- Open the Arduino IDE.
-
Go to
Sketch
>
Include Library
>
Add .ZIP Library...
. - Navigate to the downloaded ZIP file and select it to install.
FAQ
-
Is this library designed for the DHT22 sensor as well?
No. The library caters exclusively to the DHT11 sensor. The DHT22 uses a different data format, necessitating a separate library. -
What’s the recommended frequency for sensor readings?
It’s best to allow at least 1 second between readings for accurate and stable results. -
I’m experiencing persistent timeout errors. What can I do?
Ensure proper wiring, verify the sensor’s power source, and check if the specified data pin in the Arduino code matches your hardware setup. -
Has this library been tested on platforms other than the Arduino IDE?
While it’s been primarily tested on the Arduino IDE and Arduino Uno R3 board, it might work on other platforms or boards. However, results may vary. -
Is the library compatible with third-party platforms?
Although tailored for the Arduino IDE, the library might function on other platforms. Still, I don’t guarantee compatibility or consistent outcomes on third-party platforms.
Introduction
This Arduino library is designed for the DHT11 temperature and humidity sensor. It simplifies the process of reading temperature and humidity data, making it easy to integrate the DHT11 sensor into your Arduino projects.
Author:
Dhruba Saha
Version:
2.1.0
License:
MIT
Lời kết
Qua bài hôm nay các bạn biết cách làm thế nào để đọc một cảm biến nhiệt độ, độ ẩm DHT11, và hiểu hơn về cách giao tiếp của chúng.
Để nhận được nhiều kiến thức mới các bạn Đăng ký để nhận được thông báo sớm nhất.
Tham gia Cộng đồng Arduino KIT để cùng nhau thảo luận và chia sẽ kiến thức về lập trình Arduino.
Nếu các bạn thấy bài viết bổ ích nhớ Like và Share cho mọi người cùng đọc nhé.
Chúc các bạn thành công.
Trân trọng.
Doubts on how to use Github? Learn everything you need to know in this tutorial .
Find anything that can be improved? Suggest corrections and new documentation via GitHub.
DHTlib
Sensors
AVR Optimized Library for DHT Temperature & Humidity Sensor on AVR only.
Author: Rob Tillaart
Maintainer: Rob Tillaart
Compatibility
This library is compatible with the
avr
architecture so you
should be able to use it on the
following Arduino boards:
Compatibility Note
Note:
while the library is supposed to compile correctly on these architectures,
it might require specific hardware features that may be available only on some boards.
Releases
To use this library, open the
Library Manager
in
the
Arduino IDE and install it from there.
Doubts on how to use Github? Learn everything you need to know in this tutorial .
Find anything that can be improved? Suggest corrections and new documentation via GitHub.
DHTlib
Sensors
AVR Optimized Library for DHT Temperature & Humidity Sensor on AVR only.
Author: Rob Tillaart
Maintainer: Rob Tillaart
Compatibility
This library is compatible with the
avr
architecture so you
should be able to use it on the
following Arduino boards:
Compatibility Note
Note:
while the library is supposed to compile correctly on these architectures,
it might require specific hardware features that may be available only on some boards.
Releases
To use this library, open the
Library Manager
in
the
Arduino IDE and install it from there.
Arduino ESP library for DHT11, DHT22, etc Temp & Humidity Sensors
Optimized libray to match ESP32 requirements. Last changes: Fix negative temperature problem (credits @helijunky)
Filename | Release Date | File Size |
DHT_sensor_library_for_ESPx-1.19.0.zip | 2023-04-14 | 29.40 KiB |
DHT_sensor_library_for_ESPx-1.18.0.zip | 2021-02-20 | 29.33 KiB |
DHT_sensor_library_for_ESPx-1.17.0.zip | 2019-10-06 | 29.95 KiB |
DHT_sensor_library_for_ESPx-1.16.0.zip | 2019-10-05 | 29.93 KiB |
DHT_sensor_library_for_ESPx-1.14.0.zip | 2019-09-22 | 29.79 KiB |
DHT_sensor_library_for_ESPx-1.0.13.zip | 29.72 KiB | |
DHT_sensor_library_for_ESPx-1.0.12.zip | 29.70 KiB | |
DHT_sensor_library_for_ESPx-1.0.9.zip | 2018-07-17 | 29.34 KiB |
DHT_sensor_library_for_ESPx-1.0.8.zip | 2018-07-06 | 29.19 KiB |
DHT_sensor_library_for_ESPx-1.0.7.zip | 2018-06-19 | 28.86 KiB |
Examples
All examples provided use Arduino UNO’s digital pin 2 as the default connection to the DHT11 sensor’s data pin. Modify this in the code if using a different pin.
-
Read Humidity
This example demonstrates how to simply read the humidity value from the DHT11 sensor and display it on the Arduino Serial Monitor. It’s a basic introduction to using the library to get humidity data. -
Read Temperature and Humidity
A more comprehensive example that shows how to read both temperature and humidity values from the DHT11 sensor. Results are displayed on the Arduino Serial Monitor, giving users a complete view of the environment. -
Read Temperature
Similar to the ‘Read Humidity’ example, but focused solely on reading and displaying the temperature value from the DHT11 sensor. It provides a straightforward way to monitor temperature using the library. -
Read Plot
A visually interactive example that uses the Arduino Serial Plotter to graphically display temperature and humidity data in real-time. This is perfect for those who want a visual representation and trend analysis of the sensor’s readings.
How It Works
The DHT11 sensor uses a custom single-wire protocol for communication. The basic process for reading data involves:
- Sending a start signal to the DHT11 sensor.
- Reading a series of pulses from the sensor representing data bits.
- Interpreting the received bits to extract temperature and humidity values.
- Validating the data using a checksum.
The library handles these steps internally, providing the user with a simple interface for reading temperature and humidity.
Internal Protocol Handling
The library initiates the data request to the DHT11 sensor and then reads a 40-bit data stream in response. The data stream is parsed to obtain accurate temperature and humidity readings. The process of reading data from the DHT11 involves multiple steps:
Source & Credit :
Mouser DHT11 Datasheet
-
Initialization and Request
:- The MCU (like an Arduino) sends a start signal by pulling the data line low for at least 18ms.
- The MCU then pulls the line high for 20-40us to indicate that it’s ready to receive a response.
-
DHT11 Response
:- Upon detecting the start signal from the MCU, the DHT11 sends a response signal.
- This response consists of a 80us low voltage level followed by an 80us high voltage level.
-
Data Transmission
:- The DHT11 transmits its data in a series of pulses. Each bit of data is represented by a specific combination of high and low voltage durations.
- A ‘0’ is represented by 50us of low voltage followed by 26-28us of high voltage.
- A ‘1’ is represented by 50us of low voltage followed by 70us of high voltage.
- The DHT11 sends 40 bits of data in total: 16 bits for humidity, 16 bits for temperature, and 8 bits for checksum.
- The checksum is the last 8 bits of the sum of the first 32 bits. It’s used to verify data integrity.
-
Data Interpretation
:- After reading the 40 bits, the MCU processes the data to extract temperature and humidity values.
- The bits are grouped to form the integral and decimal parts of the temperature and humidity readings, though the DHT11 provides only integer values.
-
Completion
:- After data transmission, the DHT11 pulls the data line low for 50us, marking the end of the communication. The MCU then pulls the line high, putting the DHT11 in a low-power standby mode.
This library abstracts these complexities, allowing users to easily read temperature and humidity values with simple function calls. Behind the scenes, it manages the signaling, data reading, and interpretation based on the DHT11’s protocol.
Updates
v2.1.0 Hotfix Latest
-
Introduced the
readTemperatureHumidity(int &temperature, int &humidity)
method, allowing for efficient simultaneous reading of temperature and humidity, streamlining the data acquisition process. - Refactored the internal data reading process, reducing code repetition and improving maintainability.
-
Enhanced error handling: Now, specific error codes are returned from the
readTemperatureHumidity
method, making it consistent with the
readTemperature
and
readHumidity
methods. - Documentation updated to reflect the new changes and provide clear guidance on using the new library version.
Note: The updates in version 2.1.0 are backward compatible with the previous versions(v2.x.x), ensuring a smooth transition for existing projects.
v2.0.0 Update
-
Changed the return type of
readTemperature()
and
readHumidity()
methods from
float
to
int
. This aligns with the DHT11 sensor’s 1-degree resolution. - Enhanced code documentation for easier maintenance and better readability.
-
Added the
getErrorString
method to return human-readable error messages based on error codes. - Major code refactoring for better maintainability and robustness.
-
Introduced the
CONTRIBUTING.md
file to guide contributors on how to effectively contribute to the library. -
Added a
CODE_OF_CONDUCT.md
to establish community guidelines and expectations for behavior. -
Introduced the
ReadPlot
example which uses the Arduino Serial Plotter to display temperature and humidity data. This example provides a visual representation of the sensor’s readings, making it easier to monitor environmental conditions in real-time. - Added ESP32/ESP8266 compatibility.
How It Works
The DHT11 sensor uses a custom single-wire protocol for communication. The basic process for reading data involves:
- Sending a start signal to the DHT11 sensor.
- Reading a series of pulses from the sensor representing data bits.
- Interpreting the received bits to extract temperature and humidity values.
- Validating the data using a checksum.
The library handles these steps internally, providing the user with a simple interface for reading temperature and humidity.
Internal Protocol Handling
The library initiates the data request to the DHT11 sensor and then reads a 40-bit data stream in response. The data stream is parsed to obtain accurate temperature and humidity readings. The process of reading data from the DHT11 involves multiple steps:
Source & Credit :
Mouser DHT11 Datasheet
-
Initialization and Request
:- The MCU (like an Arduino) sends a start signal by pulling the data line low for at least 18ms.
- The MCU then pulls the line high for 20-40us to indicate that it’s ready to receive a response.
-
DHT11 Response
:- Upon detecting the start signal from the MCU, the DHT11 sends a response signal.
- This response consists of a 80us low voltage level followed by an 80us high voltage level.
-
Data Transmission
:- The DHT11 transmits its data in a series of pulses. Each bit of data is represented by a specific combination of high and low voltage durations.
- A ‘0’ is represented by 50us of low voltage followed by 26-28us of high voltage.
- A ‘1’ is represented by 50us of low voltage followed by 70us of high voltage.
- The DHT11 sends 40 bits of data in total: 16 bits for humidity, 16 bits for temperature, and 8 bits for checksum.
- The checksum is the last 8 bits of the sum of the first 32 bits. It’s used to verify data integrity.
-
Data Interpretation
:- After reading the 40 bits, the MCU processes the data to extract temperature and humidity values.
- The bits are grouped to form the integral and decimal parts of the temperature and humidity readings, though the DHT11 provides only integer values.
-
Completion
:- After data transmission, the DHT11 pulls the data line low for 50us, marking the end of the communication. The MCU then pulls the line high, putting the DHT11 in a low-power standby mode.
This library abstracts these complexities, allowing users to easily read temperature and humidity values with simple function calls. Behind the scenes, it manages the signaling, data reading, and interpretation based on the DHT11’s protocol.
FAQ
-
Is this library designed for the DHT22 sensor as well?
No. The library caters exclusively to the DHT11 sensor. The DHT22 uses a different data format, necessitating a separate library. -
What’s the recommended frequency for sensor readings?
It’s best to allow at least 1 second between readings for accurate and stable results. -
I’m experiencing persistent timeout errors. What can I do?
Ensure proper wiring, verify the sensor’s power source, and check if the specified data pin in the Arduino code matches your hardware setup. -
Has this library been tested on platforms other than the Arduino IDE?
While it’s been primarily tested on the Arduino IDE and Arduino Uno R3 board, it might work on other platforms or boards. However, results may vary. -
Is the library compatible with third-party platforms?
Although tailored for the Arduino IDE, the library might function on other platforms. Still, I don’t guarantee compatibility or consistent outcomes on third-party platforms.
Installation
Arduino IDE Library Manager
- Open the Arduino IDE.
-
Go to
Sketch
>
Include Library
>
Manage Libraries...
. - In the Library Manager, enter “DHT11” into the search box.
- Find the DHT11 library in the list and install it.
Installing Manually from GitHub
- Download the latest release of the library from this GitHub repository as a ZIP file.
- Open the Arduino IDE.
-
Go to
Sketch
>
Include Library
>
Add .ZIP Library...
. - Navigate to the downloaded ZIP file and select it to install.
Cảm biến nhiệt độ, độ ẩm DHT11
Cảm biến độ ẩm và nhiệt độ DHT11 là cảm biến rất thông dụng hiện nay vì chi phí rẻ và rất dễ lấy dữ liệu thông qua chuẩn giao tiếp 1 wire.
Chuẩn giao tiếp 1 wire là dùng 1 chân Digital để truyền dữ liệu.
Bộ tiền xử lý tín hiệu được tích hợp trong cảm biến giúp bạn có thể đọc dữ liệu chính xác mà không phải qua bất kỳ tính toán nào.
Thông số kỹ thuật của cảm biến:
- Điện áp hoạt động: 3V – 5V (DC)
- Dãi độ ẩm hoạt động: 20% – 90% RH, sai số ±5%RH
- Dãi nhiệt độ hoạt động: 0°C ~ 50°C, sai số ±2°C
- Khoảng cách truyển tối đa: 20m
Các bạn download và cài đặt thư viện hỗ trợ sử dụng DHT11: Tại đây
Citation
To cite this library in your projects, please use the following BibTeX entry, and refer to the Zenodo badge above for the most current DOI:
@software
{dht11_arduino_library
,author
=Saha, Dhruba
,title
=DHT11 Arduino Library
,year
=2024
,doi
=10.5281/zenodo.10633701
,version
=v2.1.0
,publisher
=Zenodo
,url
=https://doi.org/10.5281/zenodo.10633701
}
Features
-
Easy to Use
: Easy to use interface for reading temperature and humidity from the DHT11 sensor. -
No External Dependencies
: The library is standalone and doesn’t require any external libraries. -
Example Sketches
: The library package includes example Arduino sketches to get you started quickly. -
Error Handling
: The library package includes Error handling mechanisms to ensure robustness.
Error Handling
The library provides clear error handling mechanisms. When reading data:
-
If there’s a timeout while waiting for a response from the sensor, the methods
readTemperature()
and
readHumidity()
& return the value
DHT11::ERROR_TIMEOUT
. -
If there’s a checksum mismatch indicating data corruption, the methods return the value
DHT11::ERROR_CHECKSUM
.
For translating these error codes to human-readable strings, the library offers the
DHT11::getErrorString(int errorCode)
method.
Examples
All examples provided use Arduino UNO’s digital pin 2 as the default connection to the DHT11 sensor’s data pin. Modify this in the code if using a different pin.
-
Read Humidity
This example demonstrates how to simply read the humidity value from the DHT11 sensor and display it on the Arduino Serial Monitor. It’s a basic introduction to using the library to get humidity data. -
Read Temperature and Humidity
A more comprehensive example that shows how to read both temperature and humidity values from the DHT11 sensor. Results are displayed on the Arduino Serial Monitor, giving users a complete view of the environment. -
Read Temperature
Similar to the ‘Read Humidity’ example, but focused solely on reading and displaying the temperature value from the DHT11 sensor. It provides a straightforward way to monitor temperature using the library. -
Read Plot
A visually interactive example that uses the Arduino Serial Plotter to graphically display temperature and humidity data in real-time. This is perfect for those who want a visual representation and trend analysis of the sensor’s readings.
Compatibility
The library has been tested and confirmed to work on the following boards:
- Arduino Uno R3 (ATmega328P – AVR architecture)
-
NodeMCU ESP32S v1.1
ESP-WROOM-32
(Tensilica Xtensa LX6 – xtensa architecture) -
NodeMCU ESP8266 v1.0
ESP8266MOD
(Tensilica Xtensa LX106 – xtensa architecture)
Given the vast number of boards and architectures available, it’s a challenge for a solo developer to test on all. Community contributions in terms of compatibility testing are highly encouraged.
Contribute by Testing
If you’ve successfully used this library on a board not listed above, please consider contributing by letting me know. This will help the community to have a broader understanding of the library’s compatibility.
-
Fork the
repository
. - Update the README with the board you’ve tested.
- Create a pull request with your changes.
Your contribution will be greatly appreciated, and it will benefit the entire Arduino community.
Sơ đồ đấu nối
Arduino Uno | Cảm biến nhiệt độ, độ ẩm DHT11 |
5V | VCC |
GND | GND |
D4 | DATA |
Các linh kiện cần thiết cho dự án:
Tên linh kiện | Số lượng | Shopee |
Arduino Uno R3 | Mua ngay | |
Dây cáp nạp | Mua ngay | |
Cảm biến nhiệt độ, độ ẩm DHT11 | Mua ngay | |
Breadboard (Board Test) | Mua ngay | |
Dây cắm (Đực – Đực) | Mua ngay |
Bạn sẽ học được gì
- Có kiến thức cơ bản về Robotics
- Chế tạo Robot dò đường thông minh
- Đánh thức nhà khoa học bên trong bạn
- Tìm hiểu thêm về Robotics, các thuật toán Robot tự động
- Kiến thức nền tảng để chế tạo các máy móc tự động phục vụ đời sống sinh hoạt, lao động sản xuất
- Kiến thức để chế tạo sản phẩm, tham gia các cuộc thi khoa học công nghệ trong nước và quốc tế
Description
An Arduino library for the DHT series of low-cost temperature/humidity sensors.
You can find DHT tutorials
here
.
Dependencies
Contributing
Contributions are welcome! Not only you’ll encourage the development of the library, but you’ll also learn how to best use the library and probably some C++ too
Please read our
Code of Conduct
before contributing to help this project stay welcoming.
Documentation and doxygen
Documentation is produced by doxygen. Contributions should include documentation for any new code added.
Some examples of how to use doxygen can be found in these guide pages:
https://learn.adafruit.com/the-well-automated-arduino-library/doxygen
https://learn.adafruit.com/the-well-automated-arduino-library/doxygen-tips
Written by Adafruit Industries based on work by:
- T. DiCola
- P. Y. Dragon
- L. Fried
- J. Hoffmann
- M. Kooijman
- J. M. Dana
- S. Conaway
- S. IJskes
- T. Forbes
- B. C
- T. J Myers
- L. Sørup
- per1234
- O. Duffy
- matthiasdanner
- J. Lim
- G. Ambrozio
- chelmi
- adams13x13
- Spacefish
- I. Scheller
- C. Miller
- 7eggert
MIT license, check license.txt for more information
All text above must be included in any redistribution
To install, use the Arduino Library Manager and search for “DHT sensor library” and install the library.
DHT sensor library
Updates
v2.1.0 Hotfix Latest
-
Introduced the
readTemperatureHumidity(int &temperature, int &humidity)
method, allowing for efficient simultaneous reading of temperature and humidity, streamlining the data acquisition process. - Refactored the internal data reading process, reducing code repetition and improving maintainability.
-
Enhanced error handling: Now, specific error codes are returned from the
readTemperatureHumidity
method, making it consistent with the
readTemperature
and
readHumidity
methods. - Documentation updated to reflect the new changes and provide clear guidance on using the new library version.
Note: The updates in version 2.1.0 are backward compatible with the previous versions(v2.x.x), ensuring a smooth transition for existing projects.
v2.0.0 Update
-
Changed the return type of
readTemperature()
and
readHumidity()
methods from
float
to
int
. This aligns with the DHT11 sensor’s 1-degree resolution. - Enhanced code documentation for easier maintenance and better readability.
-
Added the
getErrorString
method to return human-readable error messages based on error codes. - Major code refactoring for better maintainability and robustness.
-
Introduced the
CONTRIBUTING.md
file to guide contributors on how to effectively contribute to the library. -
Added a
CODE_OF_CONDUCT.md
to establish community guidelines and expectations for behavior. -
Introduced the
ReadPlot
example which uses the Arduino Serial Plotter to display temperature and humidity data. This example provides a visual representation of the sensor’s readings, making it easier to monitor environmental conditions in real-time. - Added ESP32/ESP8266 compatibility.
Troubleshooting
-
Sensor Not Responding or Constant Timeouts:
- Ensure the sensor receives the proper voltage (3.3V or 5V).
- Double-check the data pin connection to the Arduino board.
- Restart the Arduino IDE after any changes.
-
Checksum Errors:
- Ensure minimal distance between the sensor and the Arduino board.
- Check the surrounding environment for electrical noise sources.
-
Inaccurate or Unstable Readings:
- Give the sensor time to stabilize after powering on.
- Position the sensor away from direct sources of temperature or humidity changes.
-
Library Not Found in Arduino IDE:
- Confirm the library’s correct installation.
- Restart the Arduino IDE.
Usage
Basic Usage
-
Include the
DHT11.h
header file. - Create an instance of the DHT11 class, specifying the digital pin connected to the sensor’s data pin.
-
Use
readTemperature()
and
readHumidity()
methods to read the data. -
getErrorString(int errorCode)
: Returns a human-readable error message based on the provided error code.
New Methods
-
readTemperatureHumidity(int &temperature, int &humidity)
: This new method allows for simultaneous reading of temperature and humidity, reducing the complexity and time required for separate readings. It returns an
int
indicating the success or specific error encountered during the operation.
Wiring Details
The DHT11 sensor has three or four pins, depending on the variant:
-
VCC
: Connect to 3.3V or 5V on your MCU (based on your sensor’s specification). -
Data
: Connect to a digital I/O pin on your MCU (not an analog pin). For the provided examples, we use digital pin 2 by default. -
Ground (GND)
: Connect to the ground of your MCU. -
NC (No Connect)
: Some variants have this pin. It is not used and can be left unconnected.
Remember to use a pull-up resistor (typically 10kΩ) between the VCC and Data pins for reliable communication.(Optional)
Features
-
Easy to Use
: Easy to use interface for reading temperature and humidity from the DHT11 sensor. -
No External Dependencies
: The library is standalone and doesn’t require any external libraries. -
Example Sketches
: The library package includes example Arduino sketches to get you started quickly. -
Error Handling
: The library package includes Error handling mechanisms to ensure robustness.
Usage
Basic Usage
-
Include the
DHT11.h
header file. - Create an instance of the DHT11 class, specifying the digital pin connected to the sensor’s data pin.
-
Use
readTemperature()
and
readHumidity()
methods to read the data. -
getErrorString(int errorCode)
: Returns a human-readable error message based on the provided error code.
New Methods
-
readTemperatureHumidity(int &temperature, int &humidity)
: This new method allows for simultaneous reading of temperature and humidity, reducing the complexity and time required for separate readings. It returns an
int
indicating the success or specific error encountered during the operation.
Wiring Details
The DHT11 sensor has three or four pins, depending on the variant:
-
VCC
: Connect to 3.3V or 5V on your MCU (based on your sensor’s specification). -
Data
: Connect to a digital I/O pin on your MCU (not an analog pin). For the provided examples, we use digital pin 2 by default. -
Ground (GND)
: Connect to the ground of your MCU. -
NC (No Connect)
: Some variants have this pin. It is not used and can be left unconnected.
Remember to use a pull-up resistor (typically 10kΩ) between the VCC and Data pins for reliable communication.(Optional)
Documentation and doxygen
Documentation is produced by doxygen. Contributions should include documentation for any new code added.
Some examples of how to use doxygen can be found in these guide pages:
https://learn.adafruit.com/the-well-automated-arduino-library/doxygen
https://learn.adafruit.com/the-well-automated-arduino-library/doxygen-tips
Written by Adafruit Industries based on work by:
- T. DiCola
- P. Y. Dragon
- L. Fried
- J. Hoffmann
- M. Kooijman
- J. M. Dana
- S. Conaway
- S. IJskes
- T. Forbes
- B. C
- T. J Myers
- L. Sørup
- per1234
- O. Duffy
- matthiasdanner
- J. Lim
- G. Ambrozio
- chelmi
- adams13x13
- Spacefish
- I. Scheller
- C. Miller
- 7eggert
MIT license, check license.txt for more information
All text above must be included in any redistribution
To install, use the Arduino Library Manager and search for “DHT sensor library” and install the library.
Arduino library for DHT11, DHT22, etc Temp & Humidity Sensors
Filename | Release Date | File Size |
DHT_sensor_library-1.4.6.zip | 2023-11-15 | 18.43 KiB |
DHT_sensor_library-1.4.4.zip | 2022-06-27 | 18.43 KiB |
DHT_sensor_library-1.4.3.zip | 2021-10-25 | 18.36 KiB |
DHT_sensor_library-1.4.2.zip | 2021-03-16 | 18.35 KiB |
DHT_sensor_library-1.4.1.zip | 2020-12-02 | 18.31 KiB |
DHT_sensor_library-1.4.0.zip | 2020-09-16 | 18.30 KiB |
DHT_sensor_library-1.3.10.zip | 2020-05-26 | 18.21 KiB |
DHT_sensor_library-1.3.9.zip | 2020-04-19 | 18.11 KiB |
DHT_sensor_library-1.3.8.zip | 2019-11-02 | 15.83 KiB |
DHT_sensor_library-1.3.7.zip | 2019-07-19 | 13.49 KiB |
DHT11 Arduino Library
External References
Sensors
Arduino ESP library for DHT11, DHT22, etc Temp & Humidity Sensors
Optimized libray to match ESP32 requirements. Last changes: Fix negative temperature problem (credits @helijunky)
Maintainer: beegee_tokyo
This library is compatible with the esp8266, esp32, samd, avr architectures so you should be able to use it on the following Arduino boards:
Note: while the library is supposed to compile correctly on these architectures, it might require specific hardware features that may be available only on some boards.
To use this library, open the Library Manager in the Arduino IDE and install it from there.
Đọc nhiệt độ, độ ẩm (DHT11) sử dụng Arduino Uno
Cảm biến nhiệt độ, độ ẩm DHT11 là gì?
Ứng dụng trong thực tế ra sao?
Cảm biến dùng chuẩn giao tiếp gì?
Là những câu hỏi mà những ai mới nhập môn đều muốn biết.
Qua bài viết hôm này chúng ta cùng nhau tìm hiểu nhé.
Troubleshooting
-
Sensor Not Responding or Constant Timeouts:
- Ensure the sensor receives the proper voltage (3.3V or 5V).
- Double-check the data pin connection to the Arduino board.
- Restart the Arduino IDE after any changes.
-
Checksum Errors:
- Ensure minimal distance between the sensor and the Arduino board.
- Check the surrounding environment for electrical noise sources.
-
Inaccurate or Unstable Readings:
- Give the sensor time to stabilize after powering on.
- Position the sensor away from direct sources of temperature or humidity changes.
-
Library Not Found in Arduino IDE:
- Confirm the library’s correct installation.
- Restart the Arduino IDE.
Citation
To cite this library in your projects, please use the following BibTeX entry, and refer to the Zenodo badge above for the most current DOI:
@software
{dht11_arduino_library
,author
=Saha, Dhruba
,title
=DHT11 Arduino Library
,year
=2024
,doi
=10.5281/zenodo.10633701
,version
=v2.1.0
,publisher
=Zenodo
,url
=https://doi.org/10.5281/zenodo.10633701
}
Error Handling
The library provides clear error handling mechanisms. When reading data:
-
If there’s a timeout while waiting for a response from the sensor, the methods
readTemperature()
and
readHumidity()
& return the value
DHT11::ERROR_TIMEOUT
. -
If there’s a checksum mismatch indicating data corruption, the methods return the value
DHT11::ERROR_CHECKSUM
.
For translating these error codes to human-readable strings, the library offers the
DHT11::getErrorString(int errorCode)
method.
Keywords searched by users: download dht library arduino
Categories: Tìm thấy 65 Download Dht Library Arduino
See more here: kientrucannam.vn
See more: https://kientrucannam.vn/vn/