How Does a DHT11/DHT22 Temperature and Humidity Sensor Work?
Share
The DHT11 and DHT22 are the go-to sensors for measuring temperature and humidity together, and Compoden's AI build assistant helps you wire one up and read clean values on your first try. They appear in weather stations, greenhouse monitors, and home automation projects across India. This article explains how they sense heat and moisture, how they send data, and how to read them on an Arduino or ESP32.
The working principle
Each DHT module combines two sensing elements. For humidity, it uses a capacitive element: a moisture-absorbing material sits between two plates, and as the air gets more humid the material soaks up water, which changes its ability to store charge. The sensor turns that change into a humidity reading. For temperature, it uses a thermistor, a resistor whose resistance changes with heat. As the temperature rises the resistance falls in a predictable way, and the sensor converts that into a temperature value. A small chip inside reads both elements and prepares the numbers for you.
The DHT22 generally offers a wider range and finer resolution than the DHT11, while the DHT11 is cheaper and fine for basic indoor monitoring. Both measure slowly, taking a reading every couple of seconds rather than continuously.
How it outputs a signal
Rather than analog voltage or standard I2C, the DHT sensors use a single-wire digital protocol of their own. The microcontroller sends a start signal on the data pin, and the sensor replies with a stream of bits that encodes humidity and temperature plus a checksum to catch errors. This timing-based protocol is precise, which is why almost everyone uses a ready-made library instead of decoding the pulses by hand.
How you read it on a microcontroller
Wiring is simple: VCC and GND to power and ground, and the data pin to any digital pin on your Arduino or ESP32. A pull-up resistor on the data line keeps it stable, and many modules include it on the board. With a DHT library installed, you call a read function and get temperature and humidity back as ready-to-use values. Because the sensor updates slowly, you should space your readings a couple of seconds apart; reading too fast just returns the same value or an error. The checksum lets the library flag a bad reading so you can retry.
Common uses
DHT sensors are used in room monitors, greenhouse and grow-tent controllers, server-room alerts, weather dashboards, and comfort-based fan or cooler control. They are easy to use and low cost, which makes them ideal for learning. Their limits are slow updates, modest accuracy, and sensitivity to condensation, so they suit general monitoring rather than precision laboratory work.
Build it with Compoden's AI
Choosing between the DHT11 and DHT22 and getting the data line wired correctly is where the assistant helps most. Compoden's AI build assistant compares the two for your needs, confirms the wiring and pull-up resistor on your Arduino or ESP32, and points you to the right library and a clean reading loop. Describe your project, a weather station, a greenhouse monitor, or a comfort sensor, and it recommends parts and code. Browse our collection and ask the assistant as you build.
Start sensing your environment today. Browse DHT sensors at Compoden and let the AI build assistant guide you.
What is the difference between the DHT11 and DHT22? The DHT22 offers a wider measurement range and finer resolution and accuracy, while the DHT11 is cheaper and suited to basic indoor monitoring. Both measure temperature and humidity and use the same single-wire digital protocol.
How do I read a DHT sensor on Arduino? Connect VCC, GND, and the data pin to a digital pin, with a pull-up resistor on the data line. Install a DHT library and call its read function to get temperature and humidity, spacing readings a couple of seconds apart.
Why does my DHT sensor return errors? Reading too often, a missing pull-up resistor, long or loose wiring, or condensation can cause failed reads. Slow your reading rate, add the pull-up, keep wires short, and let the library's checksum trigger a retry on bad data.