The Arduino Infrared library

Before beginning with the examples, we must quickly setup the Arduino programming environment for working with Infrared signals. This part is a bit tricky, because we are going to manually install an Arduino library for working with Infrared communications.

The ArduinoIDE (version 1.6.9 has been used in this book) comes preloaded with an Infrared remote-control library. However, this library is designed for Arduino compatible robotic vehicles that are manufactured separately - it does not work directly with normal IR receivers. For straightforward working with IR devices, there is a very popular open source IR library for Arduino that was written by Ken Shirriff. We will use the Ken Shirriff IR library instead of the IR library that shipped with the Arduino IDE.

If you try to compile the IR sketches mentioned in this book directly in the Arduino IDE, without first installing the IR library by Ken Shirriff, then the following compilation error will be seen:
C:Program Files (x86)ArduinolibrariesRobotIRremotesrcIRremoteTools.cpp:5:16: error: 'TKD2' was not declared in this scope 
int RECV_PIN = TKD2; // the pin the IR receiver is connected to

In order to avoid the above problem, follow the steps mentioned below to remove the IR library that shipped with the Arduino IDE and replace it with Ken Shirriff's IR library.

First let us understand how to remove the existing library that shipped with the Arduino IDE. While removing the existing library, retain the removed folder in another location (outside the Program Files location mentioned as follows) so that if needed you may be able to use it in future. Alternately you may download it anytime from https://github.com/arduino-libraries/RobotIRremote.

  1. Browse to the Windows path C:Program Files (x86)Arduinolibraries (as shown in the following screenshot):
Figure 2: Remove preloaded IR library shipped with Arduino IDE
  1. Locate the folder titled RobotIRRemote (as shown in the preceding picture).
  2. Next, cut the RobotIRRemote folder from this location.
  3. Then, paste the RobotIRRemote folder in any other location on your computer. The location should be outside the above mentioned folder.

Performing the preceding steps will ensure that the existing library gets removed from the Arduino IDE. Now if we try to compile any of the sketches that are included in this chapter, we will receive the following errors:

C:Usersa603209Desktop	rialIR_RemoteIR_Remote.ino:1:22: fatal error: IRremote.h: No such file or directory 
#include <IRremote.h>
compilation terminated.

The preceding errors will confirm that we have successfully removed the existing library from the Arduino IDE system.

The last step will be to download and install the IR library by Ken Shirriff. The steps are outlined as follows for reference:

  1. Browse to the following GitHub location https://github.com/z3t0/Arduino-IRremote/releases:
Figure 3: Ken Shirriff IR library download from GitHub
  1. Download the latest stable release, as shown in the preceding picture. 2.1.0 was the latest release at the time of writing this book. You should download the latest library at the time of reading this book.
  2. After downloading the ZIP file, unzip the contents in a folder with the title, as shown in the following figure. Keep the name of the folder the same as the name of the ZIP file for easy reference for the future:
Figure 4: Downloaded and unzipped folder Arduino-IR Remote-master
  1. After extracting the folder, simply copy the entire folder (as shown in the following figure):
Figure 5: Copy newly downloaded library folder
  1. Then paste it inside the Arduino libraries path C:Program Files (x86)Arduinolibraries (as shown in the following figure):
Figure 6: Ken Shirrif's IR library installed

That's it! We have now successfully installed the IR library that we will use with our examples in this chapter. Now if you try to compile any of the sketches provided in this book, you will notice that the compilation will succeed, without any errors.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.114.142