Experiment with DHT11 and Arduino


DHT11 images

The DHT11 is a basic, ultra low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air, and spits out a digital signal on the data pin (no analog input pins needed). Its fairly simple to use, but requires careful timing to grab data. The only real downside of this sensor is you can only get new data from it once every 2 seconds, so when using our library, sensor readings can be up to 2 seconds old.

Compared to the DHT22, this sensor is less precise, less accurate and works in a smaller range of temperature/humidity, but its smaller and less expensive.


  • Ultra low cost
  • 3 to 5V power and I/O
  • 2.5mA max current use during conversion (while requesting data)
  • Good for 20-80% humidity readings with 5% accuracy
  • Good for 0-50°C temperature readings ±2°C accuracy
  • No more than 1 Hz sampling rate (once every second)
  • Body size 15.5mm x 12mm x 5.5mm
  • 4 pins with 0.1″ spacing

The sensor has the following 4 pins:

  • VCC (3 to 5V power)
  • Data out
  • Not connected
  • Ground

Simply ignore pin 3, it’s not used. You need to place a 10K resistor between VCC and the data pin, to act as a medium-strength pull up on the data line. The Arduino has built in pullups, so, you can turn on but they’re very weak, about 100K.

This diagram shows how we will connect for the testing sketch. Connect data to pin 2 of Arduino, you can change it later to any pin.

DHT11 images

To test the sketch, we’ll use an Arduino. You can use any micrcontroller that can do microsecond timing, but since its a little tricky to code it up, we suggest verifying the wiring and sensor work with an Arduino to start.

Begin by downloading the DHT library from Adafruit’s github repository. To download, click the DOWNLOADS button in the top right corner. Rename the uncompressed folder DHT and make sure that it contains the dht.cpp file and others. Then drag the DHT folder into the arduinosketchfolder/libraries/ folder. You may have to create that libraries sub-folder if it doesn’t exist. Restart the IDE

Now load up the Examples->DHT->DHTtester sketch
code 1

If you’re using a DHT11 sensor, comment out the line that sets the type:

  1. //#define DHTTYPE DHT22 // DHT 22 (AM2302)
and uncomment the line that says:
  1. #define DHTTYPE DHT11 // DHT 11
This will make the data appear correctly for the correct sensor. Upload the sketch!
You should see the temperature and humidity data on the serial monitor. You can see changes by breathing onto the sensor (like you would to fog up a window) which should increase the humidity.

code 2


A video: How to use DHT11 humidity and temperature sensor

You can buy this DHT11 humidity and temperature sensor at www.buildcircuit.net.

DHT11 images              module

Buy now button


BuildCircuit proudly recommends EasyEDA for circuit and PCB design

EasyEDA: A Powerful Free Circuit, Simulation & PCB Design Tool

Register now to use it for free. No Need to download. Lots of resources and Step by step tutorials