Part 4 Appendix

4.1 Add Libraries

What is Library?

A library, gathering some function definitions and header files, usually contains two files: .h (header file, including function statement, Macro definition, constructor definition, etc.) and .cpp (execution file, with function implementation, variable definition, and so on). When you need to use a function in some library, you just need to add a header file (e.g. #include <dht.h>), and then call that function. This can make your code more concise. If you don’t want to use the library, you can also write that function definition directly. Though as a result, the code will be long and inconvenient to read.

Add libraries

Some libraries are already built in the Arduino IDE, when some others may need to be added. So now let’s see how to add one. There are 2 methods for that.

Method 1

Directly import the library in Arduino IDE (take Dht as an example below). The advantage of this method is easy to understand and operate, but on the other hand, only one library can be imported at a time. So it is inconvenient when you need to add quite a lot of libraries.

Step 1: Select Sketch -> Include Library -> Add ZIP Library.

_images/image291.png

Step 2: Find Library folder, Click Open.

_images/image292.png

Step 3: When you see Library added to your libraries. Check “Include library” menu, it means you have added the library successfully. Please use the same method to add other libraries then.

_images/image293.png

Method 2

Directly copy the library to libraries/Arduino path. This method can copy all libraries and add them at a time, but the drawback is that it is difficult to find libraries/Arduino.

Step 1: Click File -> Preferences and on the pop-up window you can see the path of the libraries folder in the text box as shown below.

_images/image294.png

Step 2: Copy all Libraries in the library folder.

_images/image295.png

Step 3: Go to the path above and you will see there is a libraries folder, click to open it.

_images/image296.png

Step 4: Paste all the libraries copied before to the folder. Then you can see them in libraries folder.

_images/image297.png