HOME / COMPONENTS / DHT22 TEMPERATURE & HUMIDITY SENSOR

DHT22 Temperature & Humidity Sensor

DHT22 Sensor Aosong Electronics 2 projects

What is the DHT22 Temperature & Humidity Sensor?

The DHT22 is a digital temperature and humidity sensor that’s a step up from the common DHT11. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air, and outputs a calibrated digital signal via a single-wire bus. You’ll get readings with better accuracy and a wider range than the DHT11, making it perfect for weather stations, greenhouse monitoring, or any project where you want reliable environmental data.

It comes as a small module with four pins, often with a built-in pull-up resistor, so you can interface it directly with a microcontroller’s digital input pin. Just note that it needs a bit of timing precision in your code — the communication protocol is custom and slightly timing-sensitive, but there are libraries available for most platforms to handle that for you.

Key Specifications

SpecificationValue
Supply Voltage3.3 – 6.0 V
Output SignalDigital single-bus (data pin)
Operating Temperature Range-40 °C to +80 °C
Humidity Range0 – 100% RH
Temperature Accuracy±0.5 °C
Humidity Accuracy±2% RH (typical)
Resolution0.1 °C / 0.1% RH
Sampling Rate0.5 Hz (once every 2 seconds)
Interface / ProtocolSingle-wire serial (custom timing)
Package TypeModule (4-pin, through-hole / male header)
Maximum Current (during conversion)1.5 mA

Pinout

PinNameTypeDescription
1VCCPWRPower supply input — connect to 3.3V or 5V.
2DATAI/OSingle-bus data line for communication with the microcontroller.
3NCNCNo connection on most modules; may be used for optional external pull-up.
4GNDGNDGround connection — connect to common ground with the microcontroller.

Note: Pin numbering and labeling can vary between module manufacturers and revisions. Always double-check against the datasheet for your specific batch.

Common Use Cases

Wiring Example

For the most common setup with an Arduino Uno, connect pin 1 (VCC) to the 5V rail, and pin 4 (GND) to ground. Connect pin 2 (DATA) to any digital I/O pin, for example Arduino pin D2. If your module doesn’t have an onboard pull-up resistor, add a 4.7 kΩ resistor between the DATA pin and VCC. That’s it — just power and one data wire, and you’re ready to read sensor values with a DHT22 library.

Tips and Gotchas

Now go wire it up and start measuring your world — happy making!

Tutorial

With the DHT22 sensor and a microcontroller, you can build temperature and humidity monitors, data loggers, weather stations, and HVAC control systems.

Wiring

Component PinBoard PinNotes
VCC5VPower
GNDGND
DATAD2Data line

Required Libraries

  • DHT sensor libraryTools > Manage Libraries > search DHT sensor library

Steps

  1. Wire the DHT22 as shown above. Connect VCC to 5V, GND to GND, and DATA to digital pin 2.
  2. Install the DHT sensor library by Adafruit via Library Manager.
  3. Upload the sketch.

Code

// Complete working sketch for DHT22 on Arduino Uno
#include <DHT.h>

#define DHTPIN 2
#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println(F("DHT22 test!"));
  dht.begin();
}

void loop() {
  delay(2000);
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  if (isnan(h) || isnan(t)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }
  Serial.print(F("Humidity: "));
  Serial.print(h);
  Serial.print(F("%  Temperature: "));
  Serial.print(t);
  Serial.println(F("°C"));
}
PlatformIO config platformio.ini
[env:uno]
platform = atmelavr
board = uno
framework = arduino
lib_deps =
    adafruit/DHT sensor library

A 10kΩ pull-up resistor between DATA and VCC is recommended for reliable communication.

Wiring

Component PinBoard PinNotes
VCC3.3VPower (works at 3.3V)
GNDGND
DATAGPIO4Data line

Required Libraries

  • DHT sensor libraryTools > Manage Libraries > search DHT sensor library

Steps

  1. Wire the DHT22 as shown above. Connect VCC to 3.3V, GND to GND, DATA to GPIO4.
  2. Install the DHT sensor library by Adafruit via Library Manager.
  3. Upload the sketch.

Code

// Complete working sketch for DHT22 on ESP32
#include <DHT.h>

#define DHTPIN 4
#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(115200);
  Serial.println(F("DHT22 test on ESP32!"));
  dht.begin();
}

void loop() {
  delay(2000);
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  if (isnan(h) || isnan(t)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }
  Serial.print(F("Humidity: "));
  Serial.print(h);
  Serial.print(F("%  Temperature: "));
  Serial.print(t);
  Serial.println(F("°C"));
}
PlatformIO config platformio.ini
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
    adafruit/DHT sensor library

DHT22 can be powered directly from 3.3V on ESP32 — no level shifter needed. Use GPIO numbers as shown.

Join the Community on Discord

Ask questions, share your builds, and hang out with fellow makers.

discord.banner_cta