DHT library not getting recognised

I am using Arduino Uno to test humudity sensor. Have downloaded the required library but still its not working.

code:-

#include <dht.h>

dht DHT;

#define DHT11_PIN 7

void setup(){
  Serial.begin(9600);
}

void loop()
{
  int chk = DHT.read11(DHT11_PIN);
  Serial.print("Temperature = ");
  Serial.println(DHT.temperature);
  Serial.print("Humidity = ");
  Serial.println(DHT.humidity);
  delay(1000);
}

error - exit status 1 dht.h: No such file or directory

so how to resolve the problem?

PS - I am new to this :slight_smile:

Somewhere on your system is the directory where you installed your Arduino IDE. You can use your computer's search facility (e.g., Windows Explore) to find out where the directory that holds arduino.exe is located. Within that directory is a subdirectory name libraries. Your DHT library files need to be located in the libraries subdirectory for the Arduino IDE to find it.

Did you install the DHT library? If not, open up the IDE, go to Sketch -> Inlcude Library -> Manage Libraries and then search for DHT and install it.

sul97:
Have downloaded the required library

Where did you download it from?

Did you install it after downloading it?:
https://www.arduino.cc/en/Guide/Libraries

econjack:
Somewhere on your system is the directory where you installed your Arduino IDE. You can use your computer's search facility (e.g., Windows Explore) to find out where the directory that holds arduino.exe is located. Within that directory is a subdirectory name libraries. Your DHT library files need to be located in the libraries subdirectory for the Arduino IDE to find it.

You should never install libraries to the Arduino IDE installation folder. The reason is that everything in the Arduino IDE installation folder is lost every time you update to a new IDE version. The correct place to install them (and the place where the Arduino IDE's Sketch > Include Library > Manage libraries.. and Sketch > Include Library > Add .ZIP Library... install to) is the libraries subfolder of the sketchbook folder. You can find the location of the sketchbook folder in the Arduino IDE at File > Preferences > Sketchbook location.

pert:
You should never install libraries to the Arduino IDE installation folder. The reason is that everything in the Arduino IDE installation folder is lost every time you update to a new IDE version.

Which is exactly why I don't do it that way. I can back up all the way to Rel. 1.05 if I want to and check out the original libraries. I prefer it that way.

i got that error just via ide install adrafruit lib for dht the lastest and i should do the job

econjack:
I prefer it that way.

Well if that makes sense for some weird specialized requirements of yours, go ahead. But that doesn't mean you should go giving horrible advice to random Arduino beginners who are only ever going to have one IDE version at a time installed.

I seriously doubt that I'm the only person here who has had to "retreat" to an earlier version of the IDE, or the suite of library files, or both. My post simply suggested that placing libraries in the libraries subdirectory is necessary for the compiler to find the include files.

Thanks for help :slight_smile:

I installed the latest library within arduino IDE itself before. Also i added a new line of code:-

#include <dht.h>

but now i got a new error :- 'dht' does not name a type

does it mean that I am moving foward and what does it mean?

Post a link to where you got the library from. Please use the chain links icon on the toolbar to make it clickable. Or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries) then say so and state the full name of the library.

pert:
Post a link to where you got the library from. Please use the chain links icon on the toolbar to make it clickable. Or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries) then say so and state the full name of the library.

Library which i am using is DHT library sensor from adafruit version 1.3.0.

I found it from Sketch > Include Library > Manage Libraries > DHT library sensor from adafruit version 1.3.0.

I installed the update and recieved this error:-
exit status 1
Error compiling for board Arduino/Genuino Uno.

sul97:
Library which i am using is DHT library sensor from adafruit version 1.3.0.

I found it from Sketch > Include Library > Manage Libraries > DHT library sensor from adafruit version 1.3.0.

That library does not contain a file named dht.h, so it's not the library you're using. It does contain a file named DHT.h but filenames are case sensitive in Arduino sketches, even on filename case insensitive operating systems.

Please do this:

  • File > Preferences > Show verbose output during: > compilation (check) > OK
  • Sketch > Verify/Compile
  • After the compilation fails you'll see a button on the right side of the orange bar "Copy error messages". Click that button.
  • Paste the error messages in a reply here USING CODE TAGS (</> button on the toolbar).

Here is the code:-

#include <dht.h>

#define DHTPIN 7
#define DHTTYPE DHT11

DHT dht;
DHT dht(DHTPIN,DHTTYPE);


void setup(){
  Serial.begin(9600);
  Serial.println("Humidity");
  dht.begin();
}

void loop()
{
  
}

and the error message below

Arduino: 1.8.7 (Windows 8.1), Board: "Arduino/Genuino Uno"

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\sultan\Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10807 -build-path C:\Users\sultan\AppData\Local\Temp\arduino_build_727354 -warnings=none -build-cache C:\Users\sultan\AppData\Local\Temp\arduino_cache_569575 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.2.1.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-5.4.0-atmel3.6.1-arduino2.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino14.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\sultan\sketch_oct04a\sketch_oct04a.ino
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\sultan\Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10807 -build-path C:\Users\sultan\AppData\Local\Temp\arduino_build_727354 -warnings=none -build-cache C:\Users\sultan\AppData\Local\Temp\arduino_cache_569575 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.2.1.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-5.4.0-atmel3.6.1-arduino2.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino14.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\sultan\sketch_oct04a\sketch_oct04a.ino
Using board 'uno' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Using core 'arduino' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Detecting libraries used...
"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10807 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\standard" "C:\\Users\\sultan\\AppData\\Local\\Temp\\arduino_build_727354\\sketch\\sketch_oct04a.ino.cpp" -o nul
"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10807 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\Users\\sultan\\Documents\\Arduino\\libraries\\DHTLib" "C:\\Users\\sultan\\AppData\\Local\\Temp\\arduino_build_727354\\sketch\\sketch_oct04a.ino.cpp" -o nul
"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10807 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\Users\\sultan\\Documents\\Arduino\\libraries\\DHTLib" "C:\\Users\\sultan\\Documents\\Arduino\\libraries\\DHTLib\\dht.cpp" -o nul
Generating function prototypes...
"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10807 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\Users\\sultan\\Documents\\Arduino\\libraries\\DHTLib" "C:\\Users\\sultan\\AppData\\Local\\Temp\\arduino_build_727354\\sketch\\sketch_oct04a.ino.cpp" -o "C:\\Users\\sultan\\AppData\\Local\\Temp\\arduino_build_727354\\preproc\\ctags_target_for_gcc_minus_e.cpp"
"C:\\Program Files (x86)\\Arduino\\tools-builder\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\Users\\sultan\\AppData\\Local\\Temp\\arduino_build_727354\\preproc\\ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10807 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\Users\\sultan\\Documents\\Arduino\\libraries\\DHTLib" "C:\\Users\\sultan\\AppData\\Local\\Temp\\arduino_build_727354\\sketch\\sketch_oct04a.ino.cpp" -o "C:\\Users\\sultan\\AppData\\Local\\Temp\\arduino_build_727354\\sketch\\sketch_oct04a.ino.cpp.o"
sketch_oct04a:6:1: error: 'DHT' does not name a type

 DHT dht;

 ^

sketch_oct04a:7:1: error: 'DHT' does not name a type

 DHT dht(DHTPIN,DHTTYPE);

 ^

C:\Users\sultan\sketch_oct04a\sketch_oct04a.ino: In function 'void setup()':

sketch_oct04a:13:6: error: expected unqualified-id before '.' token

   dht.begin();

      ^

Using library DHTLib in folder: C:\Users\sultan\Documents\Arduino\libraries\DHTLib (legacy)
exit status 1
'DHT' does not name a type

sul97:
Using library DHTLib in folder: C:\Users\sultan\Documents\Arduino\libraries\DHTLib (legacy)

That is a different library from the DHT Sensor Library by Adafruit that you installed. You need to refer to the documentation and/or example sketches of the library you're actually using.

Also posted at:
https://arduino.stackexchange.com/q/56632
and
https://stackoverflow.com/q/52652786

If you're going to do that then please be considerate enough to add links to the other places you cross posted. This will let us avoid wasting time due to duplicate effort and also help others who have the same questions and find your post to discover all the relevant information. When you post links please always use the chain links icon on the toolbar to make them clickable.