Skip to content
  1. LuzineDebug
  2. Electronics & Arduino
  3. fatal error: Adafruit_Sensor.h: No such file or…
Electronics & Arduino Beginner ≈ 5 min to fix

Fix "fatal error: xxx.h: No such file or directory" in the Arduino IDE

Error message
fatal error: Adafruit_Sensor.h: No such file or directory
compilation terminated.
exit status 1
Error compiling for board Arduino Uno.
  • sketch_nov28a.ino:1:10: fatal error: DHT.h: No such file or directory 1 | #include <DHT.h> | ^~~~~~~ compilation terminated.
  • Compilation error: Adafruit_Sensor.h: No such file or directory
  • fatal error: WiFi.h: No such file or directory
  • fatal error: ESP8266WiFi.h: No such file or directory
  • exit status 1 Error compiling for board ESP32 Dev Module.
In short

The compiler cannot find the header file included with #include: the library that provides it is not installed, or the selected board is wrong. Install the library (and its dependencies) from the Library Manager, check Tools > Board, then compile again.

Be the first to confirm this fix

What this error means

Before compiling, the C++ preprocessor replaces each #include <file.h> with the content of that file. It looks for it in the sketch folder, in the installed libraries (libraries folder of the sketchbook) and in those shipped with the core of the selected board (AVR, ESP32, ESP8266…). If it finds it nowhere, avr-gcc or xtensa-gcc stops at once with fatal error and compilation terminated. The IDE then sums up with exit status 1 and Error compiling for board … (IDE 1.8) or Compilation error: … (IDE 2). The file name tells you which library or core is missing.

Common causes

  1. Library not installed: the sketch comes from a tutorial using DHT.h, Adafruit_SSD1306.h or LiquidCrystal_I2C.h, never installed on your machine.
  2. Missing dependency: the library is there, but it includes another missing library, typically Adafruit_Sensor.h (the "Adafruit Unified Sensor" package) for DHT and BME280 sensors.
  3. Wrong board selected: WiFi.h for ESP32 or ESP8266WiFi.h only exist if the matching core is installed and selected; with "Arduino Uno", they cannot be found.
  4. Library in the wrong place: ZIP extracted into an extra subfolder (Lib-master/Lib-master/), copied outside the libraries folder, or sketchbook moved.
  5. Wrong name or case: #include <dht.h> instead of DHT.h (macOS and Linux are case-sensitive), or a local file included with <> instead of quotes.

Step-by-step fix

  1. Spot the missing file

    Read the name right after fatal error:: that is what you need to provide. If the error comes from a library file (path inside libraries/), a dependency of that library is missing.

  2. Install the library from the manager

    Open Sketch > Include Library > Manage Libraries (Ctrl+Shift+I, or the Library icon on the left in IDE 2), search for the file or component name and install it. When the IDE offers to install dependencies, choose "Install all".

  3. Or from the command line with arduino-cli

    The names to install are the Library Manager names, not the .h file names.

    bash
    arduino-cli lib search "DHT sensor"
    arduino-cli lib install "DHT sensor library" "Adafruit Unified Sensor"
    arduino-cli lib list
  4. Check the board and install its core

    In Tools > Board, pick the actual board. For WiFi.h on ESP32, add the Espressif core URL in File > Preferences > Additional boards manager URLs, then install "esp32 by Espressif Systems" from the Boards Manager.

    bash
    arduino-cli core update-index --additional-urls https://espressif.github.io/arduino-esp32/package_esp32_index.json
    arduino-cli core install esp32:esp32 --additional-urls https://espressif.github.io/arduino-esp32/package_esp32_index.json
    arduino-cli compile --fqbn esp32:esp32:esp32 MySketch
  5. ZIP library: install it in the right place

    Use Sketch > Include Library > Add .ZIP Library. When copying by hand, the library folder must directly contain its .h files (or a src/ folder) and sit in the sketchbook libraries folder. Restart the IDE afterwards.

    plaintext
    # Windows: Documents\Arduino\libraries\DHT_sensor_library\DHT.h
    # macOS:   ~/Documents/Arduino/libraries/DHT_sensor_library/DHT.h
    # Linux:   ~/Arduino/libraries/DHT_sensor_library/DHT.h
  6. File from your own project: quotes and exact case

    A .h placed next to the .ino is included with quotes, and its name must have exactly the same case as the file.

    cpp
    #include <DHT.h>       // installed library
    #include "config.h"    // file in the sketch folder
  7. Turn on verbose output if it still fails

    In File > Preferences, tick "Show verbose output during compile". The Using library … at version … in folder: and Multiple libraries were found for lines show which library is really used.

Did this fix work for you?

Confirm it in one click: it will rise for the next developers stuck on the same error.

Keep it from coming back

  • Write at the top of each sketch the required libraries with their exact Library Manager name and version.
  • For a shared project, use PlatformIO or an arduino-cli sketch.yaml: dependencies are declared there and installed automatically.
  • Select the board before opening an example: the examples and libraries offered depend on the selected board.

Frequently asked questions

I installed the library, why does the error persist?

Often the missing file is a dependency (for example Adafruit_Sensor.h), or several versions of the library coexist. Read the exact name in the error and turn on verbose output to see the folder used.

What is the difference with "was not declared in this scope"?

Here, the .h file cannot be found and compilation stops at the #include. "was not declared in this scope" comes later: the file is included, but a function or variable is not known at that point.

What does "exit status 1 Error compiling for board" mean?

It is only the IDE summary: compilation failed. The real error is higher up in the console, on the first line containing error:.

Useful tools for this error

More Electronics & Arduino errors

All Electronics & Arduino errors →