Blog
DHT22 (AM2302) Sensor: Complete Guide from Basics to Arduino Tutorial
When using the DHT22 sensor and 5V voltage, an external 5.1K pull-up resistor needs to be connected to maintain the circuit at a high level. The DHT22 uses the 1-Wire communication and can be used with a microcontroller for data transmission and interaction. When transmitting data, the DHT22 sends 40-bit data. In the application, the measurement frequency should be at least 2 seconds or more. Otherwise, data errors may occur. When sending data, it generally sends the data from the previous measurement. Multiple repeated transmissions of data are usually required to achieve the function of precise and rapid measurement of temperature and humidity.
The DHT22 is mainly used for measuring temperature and humidity. It has high measurement accuracy, with humidity accuracy within ±3% RH and temperature accuracy within ±0.5℃. It has a fast response speed and can provide real-time data feedback. It adopts the 1-Wire protocol.
The DHT is mainly applied in scenarios such as rural agriculture, industrial production, and daily life that require environmental monitoring or smart home applications. For example, in agriculture, it is used to monitor temperature and humidity to ensure that plants grow in an optimal environment. In smart homes, it is used to detect temperature and humidity so that air conditioners can adjust more effectively.
There are many common temperature and humidity sensors available on the market, which can be roughly classified into the following models: DHT, SHT, and BME280. Compared to others, DHT has a lower cost, good accuracy, and higher versatility, making it suitable for use in consumer electronic products. SHT has higher accuracy and stronger anti-interference ability. It is more suitable for high-precision fields such as industrial automation. The BME series has more measurement parameters and a longer lifespan. It is suitable for use in environments such as agriculture that require long-term and multi-parameter monitoring.
In the DHT series, the DHT11 and DHT22 are more commonly used. The DHT22 is an upgraded version of the DHT11, and its various performance parameters are superior to DHT11. However, the price of the DHT22 is slightly higher than DHT11. In terms of temperature measurement, the DS18B20 is also widely used. Here is a detailed comparison between them:
The disadvantage of the DHT22 is that its sampling frequency is not high. It requires two seconds for sampling. If the frequency is too high or too low, it will affect the output data. Moreover, it is not suitable for extremely harsh environments. If you only need to measure one parameter, there are better options available.
①:VCC ②:DATA(SDA) ③:NC ④:GND
VCC: This is used to provide power to the circuit. When connected to a 5V power source, a 5.1k ohm pull-up resistor is required to maintain a high level.
DATA: This is used for data transmission and reception between the AM2302 and the microcontroller. It uses 1-Wire transmission protocol and can be used to adjust and control the AM2302 module.
NC: This pin has no application function.
GND: This pin is grounded and is used to stabilize the circuit and reduce interference..
First, connect the VCC interface of the DHT22 to the 5V interface of Arduino. Connect the GND interface to the corresponding GND interface. Connect the SDA interface to the SDA pin of Arduino
After installing the DHT library in Arduino IDE, proceed with code uploading.
Computational results:
The specific connection reference diagram is as follows:
Software part: Open Arduino IDE, add the DHT,Adafruit_GFX, Adafruit_SSD1306 library in the library manager, then input the code and upload it to Arduino.
The demonstration video is as follows:
Yes, AM2302 and DHT22 are the same thing, just with different packages. DHT22 is usually in SMD packaging, while AM2302 is typically in a single-column surface-mount type packaging. There is no difference in their application functions in the circuit.
Considering factors such as price and application scope, the DHT22 is relatively inexpensive. It has a wide measurement range and high accuracy, and is suitable for most DIY enthusiasts to use in the electronic field.
Generally speaking, when using a 5V voltage with DHT22, a 5.1K pull-up resistor is required to keep DHT22 in a normal high level state. The reason is that DHT22 uses 1-Wire communication protocol and its pins are open-drain outputs. Commonly, it cannot actively pull up the voltage and requires a pull-up resistor to keep VCC at the corresponding voltage.