Adding a New Library to Arduino IDE and Using It

 

Let’s see how to add a library to Arduino IDE for MPU6050 (Gyroscope + Accelerometer + Temperature) module in Arduino IDE.

Step 1

Here, we will be using Korneliusz Jarzebski’s MPU6050 library from GitHub.

Download this library from here.

Download and extract the library and add its folder in the libraries folder of Arduino IDE.

Example: See the image given below. The added library is highlighted. The library folder in Arduino already consists of many libraries like WiFi, GSM, etc. Hence, their folders are present from the time of download of the Arduino IDE.

 

Step 2

Once this is done, open the Arduino IDE. We can find the examples from the added library in the Examples tab under Examples for Any Board as shown below.

Note: If you had the Arduino IDE open while adding any library, you will need to close the IDE and open it again for it to appear in the Examples tab.

 

Step 3

We can select any one of the example sketches from the added library. For example, we can select MPU6050_accel_simple sketch and directly upload it to our board just like we do for built-in examples.

It is also possible to use the functions defined in this library by simply including the header file for this library in the application sketch that we create.

Just like we include standard libraries like stdio.h, string.h, etc. include the MPU6050.h in your application sketch.

Once this is done, we can use any of the functions that are declared in the MPU6050.h file (defined in the MPU6050.cpp file) in our application sketch.

 

This process can be done for any custom library that we want to add and use.


Components Used

Arduino UNO
Arduino UNO
1
Arduino Nano
Arduino Nano
1
Ad