An Introduction to Arduino Libraries
2021-04-21 | By Maker.io Staff
When working with the Arduino IDE, you will inevitably hit a point when you have to load an external library to add functionality to an Arduino project. This article guides you through the basics of Arduino libraries. It explains what they are, where to get them, and the most common ways of installing a software library within the Arduino IDE.
What are Arduino Libraries, and Where Do I Get Them?
Arduino libraries are typically small packages of code that somebody else wrote for a particular purpose. One example is a library that adds support for a specific sensor, such as the BME280. Utilizing libraries means you don’t have to know a sensor or module inside-out to connect it to an Arduino and try it. Furthermore, you don’t have to reinvent the wheel if a library exists that already implements a commonly used feature (e.g., mathematical functions such as vector and matrix calculations).
The Arduino IDE comes with a few built-in libraries right away, which you can find a list of here. Besides these, you can typically find new libraries that add support for breakout modules on the vendor’s or manufacturer’s website. As everyone is free to write their own Arduino libraries, you can also download new libraries on many personal websites and blogs. When you manually download a library for the Arduino IDE, you typically end up with a single zip file that contains all the code files. There is, however, also an easier way of installing Arduino libraries with the library manager.
Install an Arduino Library Using the Library Manager
To install an Arduino library using the Arduino IDE’s built-in library manager, you first have to open the library manager by using the Arduino IDE’s main menu bar:
Once you choose the ‘Manage Libraries…’ option from the ‘Tools’ section, you should see that the following window pops up:
You can use the search bar, located in the top-right corner of the library manager window, to search for libraries. In this example, I searched for a library that adds support for the BME280 sensor. Once you have entered a search term, the library manager lists a few choices. Hover over the one you’d like to install and select a version. Usually, you want to install the latest version. Once done, click the ‘Install’ button, and the library manager takes care of everything else for you!
Manually Install a Library Using a Zip File
You can also use the Arduino IDE to install a library that you manually downloaded as a zip file. First, make sure not to unzip the file. Then select the ‘Add .ZIP Library…’ option from the Arduino IDE’s main menu bar:
Doing so opens up a dialog where you can select the zip archive you just downloaded. Once you select it, the IDE is going to install the downloaded library for you.
Manually Adding a Downloaded Library to the Arduino IDE
You can also add a manually downloaded library to the Arduino IDE yourself. For that, unzip the zip archive and then move its contents to the ‘libraries’ folder located in the Arduino IDE’s sketchbook folder. Make sure to put the extracted files in a separate folder within the ‘libraries’ directory if that’s not already the case. If you don’t know the location of the ‘libraries’ folder, you can use the settings window of the Arduino IDE to look it up:
Summary
Arduino libraries are typically small packages with code that you can use to extend the functionality of your Arduino programs. They usually add support for external modules and boards or commonly used functionalities. You can find many libraries online, and if you decide to download one manually, it will most likely be a zip archive that contains the library’s files. There are three ways to install a library in the Arduino IDE. You can use the library manager to automate the process. If you can’t find the library with the manager, you can use the zip file to install the library; as a last resort, you can always manually copy the library’s files to the ‘libraries’ folder within the Arduino IDE’s sketchbook directory.
Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.
Visit TechForum