Proje Defteri

DHT11 / DHT22 Code Generator

Generate ready Arduino code for the DHT11 or DHT22 temperature & humidity sensor in seconds. Pick the sensor type, pin and unit, then copy the code.

What is the DHT11 / DHT22 Temperature & Humidity Sensor?

The DHT11 and DHT22 are popular sensors that measure both temperature and humidity over a single digital pin. They are cheap, easy to use and form the basis of most Arduino weather stations, greenhouses and indoor-monitoring projects. This tool builds ready-to-flash code using the Adafruit DHT library, based on your chosen sensor type, pin and unit.

Wiring (Arduino Uno)

A 10k ohm pull-up resistor between DATA and VCC is recommended. Three-pin breakout boards usually include it already.

Library Setup

In the Arduino IDE, open Tools → Library Manager and install the DHT sensor library (Adafruit) and Adafruit Unified Sensor.

DHT11 vs DHT22

DHT11DHT22
Temperature range0-50°C-40-80°C
Accuracy±2°C±0.5°C
Humidity range20-80%0-100%
Refresh rate1 Hz0.5 Hz

Frequently Asked Questions

The sensor returns "nan" or fails to read.

Set the read interval to at least 2000 ms, and check the DATA pin wiring and pull-up resistor. Make sure you selected the correct DHTTYPE (DHT11 vs DHT22).

Does the same code work for both DHT11 and DHT22?

Yes. Just change the sensor type above; the code updates the #define DHTTYPE line automatically.

Can I get Fahrenheit output?

Yes, choose Fahrenheit as the unit; the code uses dht.readTemperature(true).