1. Home
  2. Knowledge Base
  3. Tutorials
  4. Arduino
  5. Intro to Arduino: Installing a Library

Intro to Arduino: Installing a Library

When trying to interface with an IC or hardware module, it is always nice to be able to reuse program code that someone else already went through the trouble of writing. This lets you skip the work of writing the basic interface and puts you at a much better starting point. Software libraries are a collection of program code that is easily included in a software project or sketch. Libraries make it very easier to share program code so that it can be improved and build upon. Many software libraries are freely available for much of the hardware available in the hobby electronics community. These libraries can be installed in the Arduino IDE by downloading the library, extracting the folder containing the library files, placing that folder in the Arduino libraries folder, and restarting the Arduino IDE.

 

Downloading a Library

Arduino libraries are available from many locations. Sometimes they are hosted on the website of a person or company, but many times they will be hosted on a code-sharing website like GitHub. Once you find a library that you want, go ahead and download it to your computer.

 

 

 

Extracting the Library

Most libraries are distributed in a compressed archive file format like ZIP or RAR. You will need to open the file with a file archive software. Windows is capable of extracting ZIP files, but you may need another piece of software to open other file types like RAR or TAR. If you need to install an archive software, I highly recommend 7-Zip. It is able to open, extract, and modify almost every compression archive format.

Once you open the compressed file, you need to find the folder that contains the .h and .cpp files (possibly the examples folder too). This could be the root directory of the compressed file. Now, you need to extract this folder from the compressed file on to your computer.

 

Installing the Library

Once you have extracted the folder containing the library files, you need to move that folder to the libraries folder inside of your Arduino sketch directory. This is usually located at Documents\Arduino\libraries. Go ahead and move the folder containing the library files (.h and .cpp) into this folder. Now, you will have to restart the Arduino IDE before the new library will show up.

 

 

 

Including the Library

Now that the library has been installed and the Arduino IDE has been restarted, you can use your new library in a sketch by including it. To include a library in your sketch, go to Sketch -> Include Library and select the library that you would like to include. This will add an #include statement to the top of your sketch that tells the compiler that it needs to include in library files with the sketch file.

Was this article helpful?

Related Articles