Placement of external header files

With Eclipse/Sloeber I'm using a DHT11 temp/humid sensor.

I ended up downloading the dht.h and dht.cpp from github and putting in my projects directory at the same level the projects sketch .cpp/.h are and then doing a #include dht.h in my sketch.

This works but is this the correct way I should be doing this? Seems to me that these should be in the projects libraries directory but I couldn't figure out how to do this. I spent quite a bit of time trying to put these in the lib dir but had no luck finding the solution.

Any ideas?

You have 3 options:

  • Install the library to the libraries subfolder of your sketchbook library folder (you can find/set the location of the sketchbook at File > Preferences > Sketchbook location). You can find instructions here: https://www.arduino.cc/en/Guide/Libraries. Most correct is to use the #include <dht.h> syntax, though #include "dht.h" will also work. This is the most common solution and allows you to access the files from any sketch.
  • Put the source files in the root of the sketch folder, as you are currently doing. Remember to use the #include "dht.h" syntax. This will cause each of the source folders to appear in the Arduino IDE as tabs, which is nice if you need to edit the files but otherwise causes clutter. This also gets kind of messy if you have multiple libraries all jumbled into the same folder together.
  • Put the library in the src subfolder of the sketch folder. Use the #include "src/dht/dht.h" include syntax. The library files will not appear as tabs in the Arduino IDE. This allows you to keep each library separated in a separate folder. This allows you to control the specific library version that will be used by the sketch. This allows you to distribute the sketch as a self contained unit rather than requiring the user to install all the library dependencies.

Excellent response. Easily understood. Seems like it's fairly straight forward....I hope :confused: