DHT Humidity and Temperature Sensor not working

I am trying to run my DTH11 on my Arduino, but I keep getting this error:

Arduino: 1.8.13 (Windows 10), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

In file included from C:\Users\llama\OneDrive\Documents\Arduino\libraries\DHT_sensor_library-1.4.2\DHT_U.cpp:15:0:

C:\Users\llama\OneDrive\Documents\Arduino\libraries\DHT_sensor_library-1.4.2\DHT_U.h:36:10: fatal error: Adafruit_Sensor.h: No such file or directory

#include <Adafruit_Sensor.h>

      ^~~~~~~~~~~~~~~~~~~

compilation terminated.

exit status 1

Error compiling for board Arduino Mega or Mega 2560.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Here is my code:


#include <DHT.h>

#define Type DHT11

int sensePn = 2;

DHT HT(sensePn, Type);

float humidity;
float tempC;
float tempF;

int dt 500;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  HT.begin();

  delay(dt); //This is if you're using an unfimiliar library. It gives to to make sure everything is set up.
}

void loop() {
  // put your main code here, to run repeatedly:
  humidity = HT.readHumidity();
  tempC = HT.readTemperature();
  tempF = HT.readTemperature(true);

  Serial.print("Humidity: " + humidity);
  Serial.println("hey")
}

Google search for "Adafruit_Sensor.h" and find out where you can download it from.
Paul

1 Like

@llamabro4, your topic has been moved to a more suitable location on the forum.

Please take some time to read How to get the best out of this forum and next apply what you've learned / read about code tags to the code in your post.

1 Like

Thank you so much Paul! Can you explain to me why that worked?

It's not a standard library. So you have to download it. And most (or maybe all) Adafruit libraries rely on other Adafruit libraries (it's a bit of a pain); this assumes that the DHT library is an Adafruit library.