I am trying to read the humidity and temperature using a DHT11 temperature sensor for an Arduino UNO using the DHT.h library. I have my code below:

#include <DHT.h>
#define dataPin 4
dht DHT;

void setup() {


void loop() {
  int readData = DHT.read11(dataPin);
  float t = DHT.temperature;
  float h = DHT.humidity;
  Serial.println("Temperature: ")
  Serial.print(" ÂșC")
  Serial.println("Humidity: ")
  Serial.print(" % ")

When compiling the program, it gives me an error:

fatal error: DHT.h: No such file or directory

I have also tried with lower case letters, but it will not work. Is there any reason why? Do I have to install it? I have tried to search for the library in the Arduino app Sketch - Include Library - Manage Libraries, but the library is not there.

  • Actually it is a custom library by adafruit. It is present at github.com/adafruit/DHT-sensor-library – svtag Sep 18 '17 at 19:27
  • adafruit/DHT-sensor-library is not the correct library for the code in the question. That code is written for a different library, which I have provided instructions for below. – per1234 Sep 18 '17 at 21:30
  • it seems nothing problem with your library. Have you calibrate your formula(math eq inside coding)? – ben Jul 9 '19 at 9:29
  1. Download https://github.com/RobTillaart/Arduino/archive/master.zip
  2. Copy the Arduino-master/libraries/DHTstable subfolder of the downloaded file to the libraries subfolder of your sketchbook folder. You can find the location of your sketchbook folder at File > Preferences > Sketchbook location in the Arduino IDE.
  3. Change the first line of your sketch from:

    #include <DHT.h>


    #include <dht.h>

Now when you try to compile the sketch you will still encounter many errors. However, these are caused by a paucity of semicolons, not by the DHT library, and thus off-topic for this question.

  • Thanks, @per1234, now it is not showing an error. But, the readings of humidity and temperature are not correct. Here the temperature is nearly 20-degree Celsius with humidity nearly 60%. But Arduino shows the temperature of 2.3-degree Celsius and humidity of 13%. Why so? How to correct this? – Naseeb Gill Jul 9 '19 at 6:10

I have had problems using some DHT library versions. I suggest that you try using a different version of dht.h

This version works for me (there are newer versions, but I recommend starting with this oldie but goldie):

dht.h (606B 6/12/2012)

//    FILE: dht.h
// VERSION: 0.1.00
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
//     URL: http://arduino.cc/playground/Main/DHTLib
// see dht.cpp file

#ifndef dht_h
#define dht_h

#if ARDUINO >= 100
 #include "Arduino.h"
 #include "WProgram.h"

#define DHT_LIB_VERSION "0.1.00"

class dht
    int read11(uint8_t pin);
    int read22(uint8_t pin);
    double humidity;
    double temperature;

    uint8_t bits[5];  // buffer to receive data
    int read(uint8_t pin);

try to download this library in this link and insert it to your ide, it works for me.


Not the answer you're looking for? Browse other questions tagged or ask your own question.