Once you are comfortable with the Arduino basics and trying to work with some sensors but can’t figure how to make them work ’cause they work in complex ways which is beyond your scope and you just want simple output data without having to learn how they actually work in depth!!! Well, in Arduino, you need additional libraries for that!
What are Libraries and why you need them?
Libraries are like a collection of code which makes it easy for you to connect or drive a sensor, module, display etc. For example, the built-in LiquidCrystal library makes it really simple to talk to character LCD displays. But not all the modules/sensors have builtin libraries instead the manufacturers provide them with their products. To use the additional libraries, you will need to install them.
Using the libraries can make your life so much easier! Remember the post about Distance Measuring with Sonar Sensor with lines of codes??
Well, with the help of NewPing library, you could do that in just a single line!!!
Serial.println( sonar.ping_cm() );
Installing Library from .zip file
- First download the library .zip file (ie: we’ll use the NewPing as example)
- Open your Arduino Ide and from the menubar go to
“Sktech-> Include Library-> Add .ZIP Library…“.
- Browse and select the .zip file you downloaded.
- Close the arduino IDE and reopen.
- You should be able to find your library in the example(if it includes).
- Now you are good to include them in your sketches!!
#include <NewPing.h> //includes the NewPing Library
follow the instructions on using the constructors and methods of the library you downloaded from the source page.
If you are having an error like this, its probably because the library files have been zipped multiple times and you need to extract them and put in your library folder manually.
See this section on the arduino forum for details.
Feel free to comment if you face trouble following any part of this tutorial or need additional help!