How to use the DHT11 Temperature – Humidity Sensor with Arduino

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

DHT11 Tutorial


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

OVERVIEW

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.

CONNECTIONS

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.

THE CODE

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(){
 
  Serial.begin(9600);
  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 
 
    DHT.read11(dht_apin);
    
    Serial.print("Current humidity = ");
    Serial.print(DHT.humidity);
    Serial.print("%  ");
    Serial.print("temperature = ");
    Serial.print(DHT.temperature); 
    Serial.println("C  ");
    
    delay(5000);//Wait 5 seconds before accessing sensor again.
 
  //Fastest should be once every two seconds.
 
}// end loop() 
TUTORIAL VIDEO
DOWNLOAD

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-02-23T17:33:09+00:00 January 8th, 2015|Tutorials|

12 Comments

  1. 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?
    Thanks!

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

    value is 0 only

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

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

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

    pins were wrong by me

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

  5. 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”

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

    Same here.

    0% and 0°C

  7. 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