Use one .h in two different sketches

Hi,
working on some kind of remote control and so I need two sketches, tx and rx, but this sketches need to share definitions.

I want to have a .h file which I can include in both sketches. Using 'Add file' doesnt work, always get a 'File not found' error, but you can be sure, the file is there and no typo!!

How can I solve this problem in Arduino IDE?

(( Other IDEs allowing to add/alter a search path, which is a straight foreward and simple method)).

With best regards
Gerhard

If it's only .h files you can place them anywhere. You need to include with

#include "fullPath/yourFile.h"

The better option is to put the files in the directory where 3rd party libraries are placed (sub directory of sketchbook).

sketchbook
+--- libraries
     +--- myDefinitionFiles
          +--- firstFile.h
          +--- secondFile.h

You can than include using

#include <firstFile.h>
#include <secondFile.h>

Not sure why you need two sketches, there are lot's of RX/TX examples in a single sketch. But if you insist, put the .h file in your personal library and include it with <>


Screenshot 2026-04-08 at 12.05.51

One important thing, make sure your .h file has a unique name.

And for what rason is there a 'Add File' menu command?

Hi @gerhard56

What syntax did you use in your #include directive?

There are two different styles of syntax that can be used. This syntax:

#include <filename.h>

causes the include path (e.g., where the libraries are installed) to be searched for the file.

This syntax:

#include "filename.h"

causes the local path to be searched, then the include path if the file was not found in the local path.

You can use either syntax to reference a header file from a library, but when the file is located in the sketch folder you must use the double quotes syntax. If you instead use the angle brackets syntax in this case, you will get the "No such file or directory" error, even when the file is present in the sketch.

It is used to add files to the sketch.

If you put the .h file in a folder in your sketchbook libraries folder then you can #include it it any file