Preview build — page text is a draft awaiting human review. Code badges come from real compiles. The flasher is real but not yet hardware-tested; the Playground is still a preview.
Compile error · library dependency

Fix “Adafruit_Sensor.h: No such file or directory” (DHT library)

The DHT sensor library needs a second library: Adafruit Unified Sensor. Install it from the Library Manager (or accept “Install all” when prompted).

All boardsUpdated 3 Nov 2026

Community draft — report a mistake

What you see

OutputOutput
In file included from libraries\DHT_sensor_library\DHT_U.cpp:15:
libraries\DHT_sensor_library\DHT_U.h:36:10: fatal error: Adafruit_Sensor.h: No such file or directory
   36 | #include <Adafruit_Sensor.h>
      |          ^~~~~~~~~~~~~~~~~~~
compilation terminated.
exit status 1

Compilation error: Adafruit_Sensor.h: No such file or directory

Adafruit splits shared code into helper libraries. The DHT sensor library depends on Adafruit Unified Sensor, and if only the first is installed, the build stops inside the library — not in your sketch.

Install the missing library and compile again; no code changes are needed.

Quick fix — try in order

  1. 1

    Install Adafruit Unified Sensor

    Library Manager (Ctrl+Shift+I) → search Adafruit Unified Sensor → Install. Scroll: the exact name is “Adafruit Unified Sensor by Adafruit”.

  2. 2

    Accept dependencies next time

    When installing DHT sensor library, Arduino IDE 2 asks to install its dependencies — choose Install all.

  3. 3

    Your sketch doesn’t need to include it

    The error comes from DHT_U.cpp inside the DHT library, which is compiled even if you only use DHT.h. Installing the dependency is the fix.

  4. 4

    Using arduino-cli or a ZIP install?

    ZIP installs never pull dependencies. Install both libraries: arduino-cli lib install "DHT sensor library" "Adafruit Unified Sensor".

Why it happens

Why does the DHT library need it?

The DHT library also offers a DHT_Unified class that follows Adafruit’s common sensor interface. That part includes Adafruit_Sensor.h, and the IDE compiles every .cpp file in a library.

Same pattern with other Adafruit libraries

BME280, BMP280, MPU6050 and TSL2561 libraries need Unified Sensor too. Displays need Adafruit GFX and BusIO — see Adafruit_I2CDevice.h: No such file.

DHT.h itself not found

That is the main library missing — see No such file or directory.

Board-specific notes

All boards: Tested versions are pinned in our guides, e.g. DHT22 with ESP32.

Parts: DHT22 · DHT11.

↑↓ to move · Enter to open