The library is a list of functions that simplify the using of a sensor or a component.
When an Arduino program begins by #include, then it is called a library.
A library is not essential in your program. Nevertheless, the library will help you to manipulate your component or to reduce your program. It’s simplest to use the library than re-write the functionalities in your program.
During the compilation of the Arduino program, the interface verify that the library is available.If the library is not included in the program, you can see the following message : “Librairie.h: No such file or directory”.
If you see other error message, you can resolve it thanks to our course about the problem of upload or compiling.
You click on “manage libraries”:
In the manager of Library, you can enter the library you want and download it:
You can import directly a library from your computer by clicking on the file manager:
There are many ways to find a library for a component. First when you find a program on internet, it is possible that the library is given with it, like in our courses for example.
Nevertheless, if you want to do your own program, there is a website with all the libraries.
Here is the list of the most useful libraries to write your program :
Component | Library | Course |
IR Remote | IRremote.zip | Course |
Temperature sensor DHT11 | DHT.zip | Course |
Clock module DS3131 | DS3231.zip | Course |
Distance sensor HC-SR04 | HC-SR04.zip | Course |
Keypad | Keypad.zip | Course |
LCD | LiquidCrystal.zip | Course |
Rfid | Rfid.zip | Course |
Servo motor | Servo.zip | Course |
Stepper motor | Stepper.zip | Course |
If you don’t find the library for your program, you can create your own library !
#include "Arduino Factory.h"
Arduino Factory::program() {
if (Serial.available() > 0){
c = Serial.read();
switch (c) {
//--------------button 0 pin RX-------------
case 'Q':
digitalWrite(button_0, HIGH);
break;
case 'R':
digitalWrite(button_0,LOW);
default:
break;
}
}
}
We will define the functions that will be in the file .h :
#ifndef ARDUINOFACTORY_H_INCLUDED
#define ARDUINOFACTORY_H_INCLUDED
class Arduino Factory
{
public:
void program();
};
#endif // ARDUINOFACTORY_H_INCLUDED
Once both files are done, you can zip it into a folder. This folder will be your new library. You just have to import it in Arduino IDE and call it in your program:
#include <Arduinofactory.h> // The library we have just created
#define button_0 0
char c=0;
uint16_t NA;
void setup() {
pinMode(button_0, OUTPUT);
Serial.begin(9600);
analogReference(INTERNAL);
}
void loop() {
Arduinofactory.program(); // The function that we have created in .ccp file
}