Arduino - Examples and Libraries
From the Arduino IDE menu, Examples are accessed via
By default, these examples are read only.
Programs that you write, and Examples you modify,
are accessed via
To add a library to your program, use
Sketch / Import Library...
| What is a Library?
| Adding a Library to the System
| Adding a Library to your program
| Writing your own
These are the 4 directories on my Windows Vista system
that contain the Examples and Libraries.
Your system is probably a bit different, but the general structure will be the same.
Depending on which location is used, the associated code and examples will appear in
different locations in the IDE menu structure.
For example, everything in
is accessed via
The Examples (programs) in the other 3 locations are available via
What is a Library?
A library is a collection of header (.h) and optional program (.cpp) files
located in a single directory.
Before it can be used, the Arduino IDE must know about it
(it must be placed in one of 2 directories).
Libraries may (and frequently do) contain examples showing how to use them.
These will always be placed in an examples directory.
Libraries should also contain a keywords.txt file which,
when present, tells the IDE how to color various strings.
The colors shown in the table are for my system and are different
from what various sources on the web claim.
(As you can see, KEYWORD1, KEYWORD2 and KEYWORD3 all have the same color
though it is obvious that the intent is for them to be different.)
The keyword and the identifier must be separated with one tab - no spaces.
||Method and function names
||setup, loop, Serial, and a few more
||Brown, bold ||#cc6600,bold
||Apparently, not used
On my system, the main Arduino keywords are defined in
All the IDE editor colors (including keywords) are defined in
The Arduino IDE I am using (1.0.5) does not provide a method (that I have found)
to edit these system colors.
However, you can presumably do it by hand.
(This is the Linux philosophy - GUI's suck, direct editing is always preferred.)
Looking at the libraries supplied with the IDE you will be sure to notice that
some keywords.txt files only include a part of the associated key terms.
This is most likely an oversight where the file was not updated when
the rest of the library changed.
Adding a Library to the System
Before you can add a library to your program,
it must be added to the system.
This is accomplished via one of these methods.
|Unzip the library and copy the included directory to one of the 2 library directories
After this, the library can be used immediately.
However, the associated examples will not be visible in the menu
until after the IDE is restarted.
|From the IDE menu, select
and select either the zip file or the un-zipped directory.
This procedure places the library (copies the file to)
Sketch / Import Library... / Add Library...
With this method, the associated examples are immediately available
(no restart required - yet the main Arduino help page
still says that a restart is necessary).
Adding a Library to your program
Once a library is known to the system,
you can add it to your program using the IDE menu via
which will add all the associated header (.h) files
with compiler directives similar to
At the bottom of the menu there may be a line,
everything above it is in the main Arduino directory,
everything below it is in your local directory.
Sketch / Import Library...
Alternatively, you can just add the #include directives manually.
||It does not matter if a sketch (program) includes all the header files in a library,
if one file is included, then
all the .cpp files in the library directory will be included when the program is linked.
This is a violation of standard practice and will cause problems
if multiple files contain methods or variables with the same names!
Writing your own
Based on the information provided above,
when you write your own libraries, be sure to include
Your name should be in every file - just because.
||These are the .h and .cpp files
||This instructs the IDE how to color key words
||One directory per example
||Explain why this library exists
||Where would we be without lawyers?
||Instructions on how to install it