HUM: DHT22
You are a beginner with Dasduino. Or electronics? A specific module caught your eye, but you do not know how to use it? Do not worry, HUM is here for you! How to Use Module (HUM) is a blog tutorials series by soldered where you will find all you need in order to begin working with your favorite module. Tutorials include: technical characteristics, work principle, instructions on how to connect module with Dasduino and the basic code. Everything else is left to your imagination.
INTRODUCTION
DHT22 or AM2303 is a capacitive sensor for air humidity and air temperature. The sensor is of excellent quality, very precise, but a bit more expensive and slower (2 seconds). In addition to the measuring device, the modul consists of an 8-bit microcontroller and OTP memory which are used to calibrate each reading. Small dimensions, low power consumption and long distance data transfer (> 20m) make it applicable to many devices.
Characteristics:
Voltage: 3.3 – 5.5V (recommended 5V)
Current: 300uA (average)
Measurement range: 0-100%RH; -40~80 °C
Accuracy: +-2%RH; +-0.5 °C
Long-term stability: +-0.5%RH/per year
Measurement time: 2s
Dimensions: 14x18x5.5mm
Diagrams below show the accuracy of readings depending on the measurements.
For more, check the datasheet.
HOW DOES THE DHT22 WORK?
Dasduino and DHT22 communicate via SDA (serial data) pin on the DHT and I/O pin on the Dasduino, making the simplified single-bus (one-wire) communication. Due to its master/slave structure, SDA pin requires an external pull-up resistor. The resistor value depends on the length of the cable between the microcontroller and the sensor. It is recommended to use 5.1k resistors for 5V voltage, while the cables of >20m in length do not require a resistor. If you are using 3.3V voltage the cable length can be of up to 1m maximum.
This is how the measuring procedure looks like:
The microcontroller sends a start signal to the SDA pin of the DHT which turns from saving to running mode. The signal usually lasts for 1ms, after which the I/O microcontroller is set to input. DHT responds with 40bit data representing relative humidity and air temperature.
HOW TO CONNECT IT TO DASDUINO?
ARDUINO CODE
For readings off the DHT22 we will use a library which can be downloaded on the GitHub. If you are unsure of how to install a new library, follow this tutorial. The sample code, as always, can be found under File – Examples, after you have installed the library. Below is our version which provides humidity and air temperature readings, and feels like temperature.