You want to do a cool project with Arduino and sensors. But you need an external library to install in Arduino. Either you don’t know how to install it or you know but you are getting error every time you try to add or even after adding library, it is showing there is no library. It is little frustrating as you are not doing anything with project but stuck in between libraries. And trying to figuring out why you are not able to add library and even after adding library, error is showing or code is not compiling. We will look 4 ways to add library in Arduino without getting error and also discuss some common error you will get while compiling with libraries. The method I am showing will solve your problem. So let’s get started.

Downloading Library:

You can download libraries from Github. Type sensor name and at the end type Github, you will get sensor library, download it. It will be in zip file.

How to check library is installed:

Go to File > Example > (You can see list here)

Check library is there or not

Method 1 (Easiest): ADD .zip Library

Open Arduino IDE. Go to Sketches > include library > Add .zip Library > select file location > click open.

Method 1 how to add Zip library

Method 1 finding location

Method 1 library added successfully

Your Library is added successfully.

Method 2 : Manage Libraries

Open Arduino IDE. Go to Sketches > include library > Manage Libraries > Type library name > install

Method 2 manage libraries

Method 2 library added

Type the name of library and click install. Drawback is only popular libraries can be found by this method.

Method 3 (Manually): Copy Paste library  to Arduino Directory

First we need to unzip our zip library. Copy the unzip library folder.

Method 3 copy library folder

And go to C:\Program Files (x86)\Arduino\libraries paste that folder in libraries.

Method 3 paste that folder hereIf your Arduino IDE was opened at that time and close it. And Again restart Arduino IDE. So it will include that library.

Method 4 (Manually): Renaming & Deleting files.

You did everything but still library is not showing up and getting errors.

Sometimes downloading library from internet, zip file name is with something master or any other name. Causes problem when when we install the library.

I am giving here one example with DHT library. You can download and try this exercise.

You can try to add DHT library with method 1 (Add .zip Library) and method 3 (Copy Paste library  to Arduino Directory). It will show library is added but when you try to compile code it will show error. Here we are going to solve this issue.

change “DHT-sensor-library-master” library folder name to only “DHT” (I am talking about only for this example you can change name according to your library name) in arduino libraries , C:\Program Files (x86)\Arduino\libraries

Method 4 renaming library folder

Also make sure folder name and file .h & .cpp file name is same. If require delete other .h & .cpp file in that folder, only keep DHT.h & DHT.cpp file with examples.

method 4 deleting other .h .cpp file

Restart the Arduino IDE. Now you can see it is complied successfully.

Common Error with Libraries and Compiling in Arduino:
  1. Make sure spelling is correct in code as well as file in Arduino libraries. look for upper case and lower case as it is case sensitive.
  2. Go to Tools > Board:Make sure Board is Arduino Uno or Nano whatever you are using. Because it is compiling code for that board. For example if I am trying to compile code of Mouse for Arduino Uno or Nano. It won’t compile because it is meant for Leonardo and Due boards only.

Set correct Board

3. Go to Tools > Port select correct port.

Set correct port

These are the most common things which causes error while compiling and Now you know how to solve it.

Till then keep learning keep making.