Using a third-party library in Arduino

ArduinoArduino BoardsArduino IDEArduino Programming Language

The general way of using third-party libraries in Arduino is to install them from Tools -> Manage Libraries. We already have a separate post to cover that. However, what if a library you are using for cannot be found in Tools -> Manage Libraries? After all, Manage Libraries only includes those libraries which are present in Arduino Library Manager −

http://downloads.arduino.cc/libraries/library_index.json

So, how do we use a library not present in Arduino Library Manager? Let's use an example to understand.

Consider the TinyGPSPlus library (https://github.com/mikalhart/TinyGPSPlus) which is not available in Arduino's Manage Libraries portal as on 17th March 2021.

In order to use this library in a particular sketch, navigate to the public libraries folder of Arduino. The path is generally (C:\Users\YourUserName\Documents\Arduino\libraries) on Windows.

Clone this library into that folder using git clone. If you are unfamiliar with git, you can download zip and extract it in the sketch folder.

The libraries folder will now contain the library −

Now, open your sketch again, and got to Sketch -> Include Library, and select the newly added library.

When you do that, you will see the following line included at the top of your sketch −

#include <TinyGPS++.h>

Congratulations, this new library is now ready to be used in your sketches!

raja
Published on 23-Mar-2021 11:42:06
Advertisements