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

Directories | What is a Library? - keywords.txt | Adding a Library to the System | Adding a Library to your program | Writing your own | References


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 where

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.

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.

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.

Alternatively, you can just add the #include directives manually.

Caution: 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.


Author: Robert Clemenzi
URL: http:// / Hardware_Platforms / Arduino / Libraries.html