How to Add a Library in Arduino

Featured How To Add A Library In Arduino

If you’ve been using Arduino IDE for a while, you would eventually need to extend its capabilities to connect with sensors, displays, Arduino shields, non-Arduino boards, and any other modules. After all, there is a limit to the number of built-in sketches you can use from the downloaded Arduino software.

However, thanks to a vibrant Arduino community, you can now access compatible programs called “libraries” which can be modified according to your needs. The following steps describe the procedure of adding Arduino libraries to the IDE.

What Is an Arduino Library?

Arduino libraries are frequently-used, readily-available programs that help you get around the IDE’s limited number of built-in sketches. Arduino defines them as “collections of codes which provide extra functionality for use in sketches”. Two examples of these functionalities would be “working with any hardware” or “manipulating data” in a software.

These add-on codes might be already installed in the IDE, or are downloadable separately as a zip folder on GitHub, Arduino.cc or other sites. If you’re using a stable Arduino version (as of now, 1.8.15 and below), you can easily locate the list of existing libraries. To view/add a library, go to “Sketch -> Include Library”, where you can preview a list of already installed libraries.

Arduino Include Libraries
Lis of already existing Arduino libraries in Arduino IDE Version 1.8.13 for Windows

As can be seen above, all the sketch examples are neatly structured in a tree that allows easy access by topic or library. The following screen displays the addition of various libraries including that of “Mouse”, “LiquidCrystal”, and “Wi-Fi”.

All libraries are identifiable by an #insert statement at the start of the code. It is an important command that helps compile the libraries with any sketch you want to create. So, if you want to add mouse, LCD and Wi-Fi (Arduino Wi-Fi shield) functionality in your project (at the user end), the following #insert statements are in order.

Arduino Included Preexisting Libraries
#Insert library commands added to an Arduino Sketch

Since libraries are uploaded to the Arduino board once you finalize the sketch, they may occupy a lot of extra space. Thus it’s important to ease up on the number of #include tags, and delete any extras from the sketch if they’re not needed.

All the libraries are physically stored in the program files in .ino format, which is an Arduino sketch file. You can view each one of these .ino sketches on your computer in a relevant sub-folder under libraries, as shown here for Windows 10.

Arduino Libraries In Ino
Arduino Libraries in .ino format

From the above menu item itself, you can access the Library Manager and import new libraries from .zip files. We have covered it separately below.

How to Install Arduino Library from Arduino Library Manager

To add Arduino libraries from the IDE’s own library manager, go to “Sketch -> Include Library -> Manage Libraries.”

Arduino Access Manage Libraries
Arduino Access Manage Libraries

If you are using Arduino’s latest 2.0 version which is still in Beta, the procedure to add libraries is the same.

Arduino Libraries New Version

You can see a drop-down range of libraries in the Library Manager. If you previously installed a lot of sketches and themes in Arduino IDE, it might take a few seconds for the libraries to update.

Arduino Libraries Updating
Arduino Libraries Updating

Click on any library by either searching for it or scrolling down the list. To install one of them, click “more info” and you will see multiple update versions of the concerned library along with an “install” button. Click install for any latest version available. Sometimes, only one version may be available.

Arduino Libraries Latest Version
Arduino libraries install latest version

The installation of the specific Arduino library should not take more than a few seconds.

Arduino Libraries Installing A Library
Arduino IDE installing a library of AudioFrequencyMeter

Once it has finished, an “Installed” tag can be seen next to the library in the Library Manager as shown below.

Arduino Libraries Installed
Arduino Library Installed tag

Also, wait for the Library Manager to update its list of libraries. This means henceforth, the new added library should be easily viewable from the Sketch menu. You can close the library manager once it’s done.

Arduino Libraries Updating List
Library Manager Updating Its List of Libraries

You can verify the presence of the added library by going back to “Sketch -> Include Library -> Contributed Libraries”.

Arduino Libraries New Library Added
Arduino new library added and visible from Sketch menu

If you want to add your own library to Library Manager as a .zip file, you can learn to do it in a section below.

How to Install Arduino Library in Arduino Version 2.0?

As discussed above, the procedure to install a library in Arduino Version 2.0 (Beta) is exactly the same as for 1.8.15 and older versions. However, the screenshots and placements of menus are slightly changed as shown here. For one, the library manager does not open as a popup box but on the left side.

Arduino Libraries 2.0 Version Library Manager

Locating and installing is pretty easy from the Arduino library menu items which can be autoscrolled as shown here. However, there may be a notification to add a few dependencies to a library. Click “Install all” to proceed.

Arduino Libraries 2.0 Version Dependency

You will be able to view the installation successful message directly on the Output screen.

Arduino Libraries 2.0 Version Succesfully Installed New Library

Accessing the newly added library in Version 2.0 is exactly the same as the previous versions, 1.8.15 and before. Go to “Include Library” in the Sketch menu.

Arduino Libraries 2.0 Successfully Added

How to Install Arduino Library by Importing a .ZIP File Automatically?

Arduino’s official website maintains a reference list of libraries that are available for download and installation. These are the ones that show up as per the above-described procedure.

Arduino Included Libraries Standard Libraries
Arduino Standard libraries

If you want to add your own library, there are two options: either create one or download an existing library which has been distributed as a .ZIP folder. We will focus on the second method as it’s easier.

If you want to set up a third-party library in Arduino IDE, you have to search for it online. GitHub is a good place to find them. It has over 100 examples. We have selected the following example for Machine Control.

Arduino Libraries Github Download Zip File
Arduino Zip File Library example available on GitHub

You will be given an option to download the zip file. Save it on your computer. Do not unzip it. In the next step, you can add the zip file from “Sketch -> Include Library -> Add .ZIP Library.”

Arduino Libraries Add Zip File
Arduino Add .ZIP library

You don’t have to unzip the folder for a proper download. The ZIP file usually contains everything you need in the coding activity, including any usage examples if the author has provided them. If there are no programming errors, it will automatically sync with Arduino IDE.

Arduino Libraries Importing Zip File
.ZIP file imported in Arduino library

Go back to the “Sketch -> Include Library” menu. You should now see the imported .ZIP file library within the list of Arduino libraries.

Arduino Libraries Zip File Library Added

After you click on the concerned Arduino .ZIP library, the .ZIP file imported library can now be viewed in the sketch window.

Arduino Libraries Zip File Library In Skecth Window

How to Manually Install a Downloaded Arduino Library?

Sometimes, you may want to perform the imported library installation process manually. For this, open the .ZIP folder manually, unzip the Master template, extract the folder and save it on another location like the Desktop.

Arduino Libraries Unzip Master Template

Now, close the Arduino IDE software and go to the “Libraries” folder in Arduino software location. Here, you can add the extracted Master folder as shown here.

Arduino Libraries Added Library Manually

Summary

Arduino libraries extend storage and functioning capabilities. This gives you far more room for maneuvering your projects. Whether you’re working with flight controllers, drones or robots, you can search its corresponding library file.

Now that we’ve learned how to add libraries to Arduino IDE, you might want to change new themes in the background which are colorful and more pleasing to the eye.

Subscribe to our newsletter!

Get the best of IoT Tech Trends delivered right to your inbox!

Sayak Boral

IoT-addicted since early 2016. Love to explore the challenges, opportunities and trend insights into what is becoming the third wave of Internet.