DHT code won't compile: two DHT libraries

  • DHT11
  • DHT22

You may see

error: 'DHT' does not name a type
error: 'class dht' has no member named
fatal error: dht.h: No such file or directory
fatal error: DHT.h: No such file or directory
fatal error: Adafruit_Sensor.h: No such file or directory

Why it happens

  • The sketch uses one library and the other is installed.
  • The Adafruit library needs the Adafruit Unified Sensor library too.

How to fix it

  1. Look at the first lines. #include <DHT.h> needs DHT sensor library by Adafruit and Adafruit Unified Sensor.
  2. #include <dht.h> needs DHTlib by Rob Tillaart.
  3. Install the one your lesson uses. Don't mix commands from both: dht.readTemperature() is Adafruit, DHT.read11(pin) is DHTlib.

It worked if: Verify passes.

From the official documentation. Both libraries compiled here with Arduino CLI; the missing-file lines came from real runs, the other two are typical compiler wording. Sources: Adafruit DHT library, DHTlib.

Didn't help? Search another error or ask us.