DHT22 Explained: How It Measures Temperature and Humidity, and How to Wire It to an ESP32

The DHT22 (sold under the chip name AM2302) is a digital temperature and humidity sensor that reads -40°C to +80°C (±0.5°C) and 0-100% relative humidity (±2-5% RH), communicating over a single proprietary data line rather than I²C or SPI. Module breakouts expose just three pins — VCC, DATA, and GND — because the pull-up resistor the data line needs is already built onto the board. It runs on anything from 3.3V to 5.5V, which is why the same module drops onto a 3.3V ESP32 or a 5V Arduino Uno without a level shifter, and it's the sensor most people reach for once a DHT11 build stops being accurate enough.

What does the DHT22 measure?

Reading Range Accuracy
Temperature -40°C to +80°C ±0.5°C
Humidity 0-100% RH ±2-5% RH

Both values come off the same chip and the same single data pin — there's no separate humidity wire. The tradeoff for that accuracy is speed: the DHT22 can only be read about once every 2 seconds. Poll it faster than that and you'll get stale or repeated values, not an error, so the timing has to be handled in firmware rather than assumed.

How does the DHT22 actually work?

Inside the module, a humidity-sensing capacitor and a thermistor feed an internal chip that digitizes both readings and pushes them out over one wire using a custom timed pulse-width protocol — not the standardized "1-Wire" bus, and not I²C or SPI despite looking like a simple 3-pin sensor. The host microcontroller sends a start signal, the DHT22 responds with 40 bits (16 for humidity, 16 for temperature, 8 as a checksum), and the receiving code has to measure the width of each pulse to decode a 0 from a 1. This is exactly why libraries exist for it: the bit-banged timing is fussy enough that hand-rolling it is rarely worth the effort when the Adafruit DHT sensor library already does it reliably.

How do you wire the DHT22 to an ESP32?

ESP32 pin DHT22 pin Signal
3V3 VCC power
GND GND ground
GPIO4 DATA single-wire digital

Three wires, no level shifter needed since the module accepts 3.3V directly. GPIO4 is a commonly free pin on most ESP32 dev boards, but any general-purpose digital pin works — the pin number just has to match whatever you set in the firmware's DHT_PIN definition. If your breakout doesn't already include the pull-up resistor on DATA, add a 10kΩ resistor between DATA and VCC.

DHT22 vs DHT11 — what's the difference?

They look identical and use the same wiring and library, which is exactly why people accidentally reach for the wrong one. The DHT11 is cheaper and reads a bit faster, but its range is narrower and its accuracy is coarser — typically around 0-50°C and 20-90% RH, with roughly ±2°C and ±5% RH accuracy and lower resolution overall. The DHT22 covers a much wider range (down to -40°C, useful outdoors or in a freezer), is roughly 4x more precise on temperature, and reads humidity down to fractional percentages instead of whole numbers. For a weather station, greenhouse controller, or anything reporting numbers a person will actually trust, the DHT22's extra accuracy is the reason it costs more.

Watch it built live: a real ESP32 + DHT22 project

Rather than describe a generic build, we typed one real sentence into Compoden's AI build assistant on the storefront and let it pick parts, price them, and explain the reasoning — unscripted, screenshotted as it happened:

"I want to build a weather monitoring project using a DHT22 and an ESP32"

Compoden AI build assistant screenshot: DHT22 weather monitoring build with parts tray

It matched four in-stock parts against the build's requirements and explained each one in plain language. On the sensor itself, it said: "The DHT22 (AM2302) Temperature and Humidity Sensor Module is the part that actually measures the temperature and humidity. It uses a single-wire digital interface, which is a simple way for it to send its readings to the microcontroller." It also flagged a real mismatch unprompted: the bundled power adapter is Micro-USB while the recommended ESP32-C3 board charges over USB-C, so an adapter or different cable is needed between the two.

Watch the firmware get generated

We then asked Compoden's build companion, Soldr, to write the actual firmware for the same project — targeting the ESP32 specifically and printing live readings to the serial monitor:

Soldr firmware editor screenshot: generated ESP32 code for the DHT22 project

The generated sketch includes the DHT.h and Adafruit_Sensor.h library includes, a DHT_PIN/DHT_TYPE definition pair, and wiring comments matching the pinout above — in this run, generated for the ESP32-C3 variant, it wired DATA to GPIO3 and noted the 10kΩ pull-up recommendation explicitly in a comment. It compiles to more than a dozen board targets beyond ESP32 variants, including Arduino Uno, Arduino Mega, and the Raspberry Pi Pico family.

So what is the DHT22 actually good for?

Anywhere a project needs trustworthy temperature and humidity numbers rather than a rough estimate: weather stations, greenhouse and grow-tent climate monitoring, HVAC control loops, indoor air-comfort dashboards, and dew-point calculations that combine both readings. Its 2-second sampling limit rules out fast-changing measurements, but for anything that changes over minutes rather than milliseconds, it's the standard step up once a DHT11 isn't precise enough.

Get everything in this build

The exact four parts Soldr picked above, at today's live price and stock — each links straight to checkout, or add the whole tray in one click.

Part Price
ESP32-C3 Super Mini Development Board ₹290 Add to cart →
DHT22 (AM2302) Temperature and Humidity Sensor Module ₹100 Add to cart →
5V 2A Micro-USB Power Adapter ₹140 Add to cart →
23 AWG Multi-Strand Breadboard Wire ₹10 Add to cart →
Total ₹540 Add all 4 to cart →

Prices and stock verified live at the time this was written; Compoden's storefront always reflects the current price at checkout.

Built and Backed by Compoden

Every part above ships from Compoden's own India stock, tested for compatibility before it's carded together — not sourced individually and hoped to work. Delivery in 3–7 days across India, with COD and UPI available at checkout. If a part in this build doesn't perform as described, Compoden's support team will help you troubleshoot or replace it.

FAQ

Is the DHT22 the same protocol as I2C or 1-Wire?
No. It uses a proprietary single-wire timed pulse protocol that looks similar to Maxim's 1-Wire bus but isn't compatible with it, and it isn't I²C or SPI despite the 3-pin form factor. It needs a dedicated library to decode the pulse timing correctly.

How often can I read the DHT22?
At most once every 2 seconds. Reading faster than that returns stale or repeated data rather than an error, so firmware should space out its read calls.

Can I power the DHT22 from a 5V Arduino and a 3.3V ESP32 with the same code?
Yes. The module accepts 3.3V to 5.5V directly, so the same wiring pattern and the same DHT library calls work on both, with only the data pin number changing between boards.

Why does my DHT22 need a pull-up resistor?
The single data line needs to idle high between readings. Most breakout modules already include this resistor on the board; if you're wiring a bare DHT22 chip instead of a module, add a 10kΩ resistor between DATA and VCC yourself.

Back to blog