☁️ DHT22 and Arduino – connection circuit
To implement the project from this article, we need the following components:
- Arduino Uno R3
- DHT22 - Temperature and humidity module
The sensor can be powered from 3.3-6 V, that is, it can be safely used with all types of Arduino. A single-wire protocol incompatible with DHT11 is used for communication. Measurement ranges - temperatures from -40 to 80 ° C, relative humidity from 0 to 100%. A typical error is ± 2% humidity and less than 0.5 ° С temperature.
Every 2 seconds the sensor is capable of issuing updated information. The transmission time of one data packet is 5 ms.
The dimensions of the sensor are 21 × 15 mm, the pitch of contacts is 2 mm, that is, they can be inserted into the solderless breadboard, but you will have to bend the legs.
The sensor provides maximum accuracy among sensors that connect via a single-wire interface - it can be used even in relatively complex projects, such as accurate weather stations or automatic irrigation of greenhouses.
DHT sensors have 4 outputs:
- Module Power (5V)
- Data output
- Not used
A 10 kΩ resistor must be placed between the power and data terminals.
CONNECTING TO ARDUINO IDE
A library from Adafruit - DHT Sensor Library can be used to work with all DHT sensors (11 and 22): LINK
You can either download it, unzip the ZIP archive and place it in the libraries subfolder in the Arduino IDE installation folder or, in the new versions of the development environment, install via the Library Manager (Sketch-Connect Library-Manage Libraries):
To work correctly, you need to install another library - Adafruit Unified Sensor: LINK
After installation, we will look at the appeared examples, specifically - on DHTtester:
All you may need to change is the sensor connection pin on line 6. Do not forget to pull the signal leg to the power line with a 10 KΩ resistor, otherwise, the sensor will not respond. Connect the sensor, open the port monitor and voila!