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

Got Questions? Click here and post them in the Brainy-Bits Forum to get help!


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() 


You can download the Library we used here:

You can download the code here:


Asargiu Daniel - Jan 06, 2017

Current humidity = 0.00% temperature = 0.00C

Paul - Jan 06, 2017

If you have smth like"Current humidity = 0.00% temperature = 0.00C", change your signal and plus pin

Theo - Jan 06, 2017

Uh…isn’t the DHT11 a digital sensor? As such, shouldn’t it be connected to a digital pin? Does it really work on an analog pin? :|

Solide - Jan 06, 2017

Hi !

Thanks for the tutorial.

Working like a charm but as stated in one of the comments, I had to invert + and output.

Current humidity = 41.00% temperature = 26.00C which is close to what my home sensor displays.

Looks like it’s definitely not digital and why other tutorials were not working …

hasnol - Jan 06, 2017

hye. when i run this code it said “exit status 1
Error compiling for board Arduino/Genuino Uno.” so wht should i do??

lorenzo - Jan 06, 2017

the dht file won’t open

Oleg - Jan 06, 2017

“Current humidity 255,00% current temperature 255,00С”
Something strange. Could you recomend something, please.

Got Questions? Click here and post them in the Brainy-Bits Forum to get help!

Leave a comment

Comments have to be approved before showing up