Operating voltage | DC 3.3 to 5.5V |
---|---|
Humidity range | 0% to 100% relative humidity |
Humidity accuracy | ±2% RH |
Temperature range | -40°C to +80°C |
Temperature accuracy | ±0.5°C |
Signal output | Single-bus, bidirectional serial data |
DHT22-Pin | Function | Arduino Uno |
---|---|---|
1 | Vdd (3.3V - 5.5V) | 3.3V or 5V |
2 | SDA (Serial Data) | D2 (or other digital Pin) |
3 | -not connected- | - |
4 | GND (Ground) | GND |
According to the datasheet for the DHT22, a pull-up resistor of 5.1kΩ must be used on the data pin.
Here, a 4.7kΩ resistor is used, as it is more common and possibly more readily available.
In some cases, this external pull-up resistor can be omitted if the library used below is utilized.
This library makes use of the Arduino's internal pull-up and delivers the same results even without
the external pull-up.
For simple control and programming of the DHT22, the following two libraries are used:
Adafruit DHT-Sensor
and
Adafruit Unified Sensor.
#include "DHT.h"
#define DHTTYPE DHT22
#define PIN_DHT22 2
DHT dht(PIN_DHT22, DHTTYPE);
float humidity, temperature;
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
humidity = dht.readHumidity();
temperature = dht.readTemperature();
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print("%, Temperature: ");
Serial.print(temperature);
Serial.println("°C");
delay(1000);
}
The second programm essentially does the same thing, with the difference that the measured values are sent to the serial interface separated by spaces. This allows the use of the serial plotter in the Arduino IDE as a graphical output of the measurements.
#include "DHT.h"
#define DHTTYPE DHT22
#define PIN_DHT22 2
DHT dht(PIN_DHT22, DHTTYPE);
float humidity, temperature;
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
humidity = dht.readHumidity();
temperature = dht.readTemperature();
Serial.print(humidity);
Serial.print(" ");
Serial.println(temperature);
delay(1000);
}