Skip to main content

Arduino How to use library

The Arduino ecosystem is so large that there are many libraries for sensors. The Arduino library makes it easy to test your sensor on Arduino board. I will explain how to use the library on Arduino.

Download library#

Find and download a required library below.

By default, the Arduino IDE searches for libraries in ~/Arduino/libraries at startup. So, move or copy the downloaded library to ~/Arduino/libraries and restart the IDE.

In general, the directory tree looks like this:

└── libraries
β”œβ”€β”€ A/
β”‚ β”œβ”€β”€ examples/
β”‚ β”œβ”€β”€ keywords.txt
β”‚ β”œβ”€β”€
β”‚ └── src/
β”‚ β”œβ”€β”€ A.cpp
β”‚ └── A.h
β”œβ”€β”€ B/
β”‚ β”œβ”€β”€ B.cpp
β”‚ β”œβ”€β”€ B.h
β”‚ └── ...
└── ...

Include library#

If you know the library header, include header using #include. If not, find the library in Sketch -> Include Library menu.

#include <A.h>
void setup() {
// ...
void loop() {
// ...

Find docs or SeeΒ example#

If you are new to the library, read the docs about it. Another good way to understand the usage is to look at examples. In general, Arduino libraries have own examples. Find the example in File -> Examples menu.

Wire sensor andΒ board#

Different sensors use differently, so you should search for this or read the datasheet. Believe God Google...


Last updated on