How to use the DHT11 Temperature – Humidity Sensor with Arduino

//How to use the DHT11 Temperature – Humidity Sensor with Arduino

DHT11 Tutorial

How to use the DHT11 Temperature and Humidity Sensor with an Arduino!


In this tutorial we will learn how to use a DHT (DHT11 version) Temperature and Humidity Sensor.

It’s accurate enough for most projects that need to keep track of humidity and temperature readings.

Again we will be using a Library specifically designed for these sensors that will make our code short and easy to write.


As you can see we only need 3 connections to the sensor, since one of the pin is not used.

The connection are : Voltage, Ground and Signal which can be connected to any Analog Pin on our UNO.


Since we will be using a Library that is available for this sensor, our code will be very short and simple.

Once you have the library, just go ahead and extract it to the Library folder inside your Arduino IDE software folder.

#include "dht.h"
#define dht_apin A0 // Analog Pin sensor is connected to
dht DHT;
void setup(){
  delay(500);//Delay to let system boot
  Serial.println("DHT11 Humidity & temperature Sensor\n\n");
  delay(1000);//Wait before accessing Sensor
}//end "setup()"
void loop(){
  //Start of Program 
    Serial.print("Current humidity = ");
    Serial.print("%  ");
    Serial.print("temperature = ");
    Serial.println("C  ");
    delay(5000);//Wait 5 seconds before accessing sensor again.
  //Fastest should be once every two seconds.
}// end loop() 

For the Arduino code, just copy and paste the code above in your Arduino IDE software.

You can download the DHT Library we used here: DHT-Library

By | 2018-07-18T23:27:35+00:00 January 8th, 2015|Tutorials|


  1. Albert September 6, 2018 at 9:39 pm - Reply

    Hello nice post. is the same code if i have the DHT22 and my arduino is mega 2560? i do the same as you but it doesnt work. Thanks!

  2. Parveen Verma July 27, 2018 at 9:13 am - Reply

    The best &easiest way you have shown to get data from DHT11 with very easy connections. thanks a ton

  3. Horacio Venturino July 24, 2018 at 10:44 am - Reply

    I like very much your presentations. For your clarity, tidy and complete documentation.
    Thanky you very much” I learn a lot.

  4. al July 24, 2018 at 5:18 am - Reply

    Probably you have different pins: 1 – signal (left), 2 – 5V (middle), 3 – GND (right)

  5. ashish July 13, 2018 at 3:38 am - Reply

    when I am uploading the program its showing that DHT director not found plz help me out

  6. Daniel June 30, 2018 at 4:43 pm - Reply

    hey! I am having a problem… it is giving me the wrong outputs, it looks something like this:
    Curdity = -999.00% temperature = -999.00C
    Current humidity = -999.00% temperature = -999.00C
    DHT11 Humidity & temperature Sensor

    Current humidity = -999.00% temperature = -999.00C
    Current humidity = -999.00% temperature = -999.00C
    Current humidity = -999.00% temperature = -999.00C

    What did I do wrong?

    • Yosuar Vazquez July 31, 2018 at 2:35 pm - Reply

      Switch the pins, you probably have signal on the far left, VCC IN MIDDLE AND ground on far right.

  7. Vivek Raj Gupta May 18, 2018 at 8:12 am - Reply

    value is 0 only

  8. Pamila Klinich May 16, 2018 at 10:46 am - Reply

    Your site is so fantastic. I’m going to come back here again.

  9. EMIL4 May 7, 2018 at 5:34 am - Reply

    pins were wrong by me

    right pin = Ground
    middle pin = VCC
    left pin = Signal

  10. ANKIT April 13, 2018 at 9:17 am - Reply

    showing compilation error for arduino uno

    • Ash June 12, 2018 at 1:57 pm - Reply

      in line 1: it should be #include “dht.h” instead of #include “DHT.h”

      • Myk July 18, 2018 at 9:38 pm - Reply

        I had to change the line #include “DHT.h” to #include “dht.h” as the .h file in the dht library that you link to does not have a DHT.h file, it has a dht.h file

        • brainy-bits July 18, 2018 at 11:29 pm - Reply

          Thank you Ash and Myk for pointing that out, I’ve gone ahead and change the code above to reflect this. Cheers!

  11. Mauricio April 9, 2018 at 8:49 pm - Reply

    Same here.

    0% and 0°C

  12. vishnu February 26, 2018 at 9:46 pm - Reply

    its doesnt work properly it shows
    Current humidity = 0.00% temperature = 0.00C
    Current humidity = 0.00% temperature = 0.00C
    Current humidity = 0.00% temperature = 0.00C
    Current humidity = 0.00% temperature = 0.00C
    Current humidity = 0.00% temperature = 0.00C
    Current humidity = 0.00% temperature = 0.00C

    • Sinon March 29, 2018 at 10:31 pm - Reply

      same here

      • hectormtc May 6, 2018 at 2:26 am - Reply

        same too : /

    • Shankara May 17, 2018 at 1:37 pm - Reply

      Make sure you have plugged your sensor in right. I think that the problem here maybe due to you plugging the sensor into the wrong analog pin. Try plugging it into a0 and change your code adequately.

    • Shankara May 17, 2018 at 1:39 pm - Reply

      The problem you have may be due to the fact that the arduino is reading data from the wrong pins. Try changing the analog pin for the sensor in the code or unplug the sensor and plug it back into the analog pin that is used in the code. For instance, I used A0, so you need to connect the sensor to the analog pin A0.

Leave A Comment