User manual
While we can connect an IR receiver to any available digital input pin, you can only use very specific
pins for output. The library uses PWM pins and modifies the timing parameters to change the
default frequency of that pin.
The default timer is TIMER2 on the Arduino Uno and Arduino Mega. On the Leonardo with is
TIMER1. The pin numbers are pin 3 for Uno and use pin 9 for the Leonardo and Mega. If you have
modified the library to use a different timer such as changing the timer number on a Leonardo to
avoid conflicts with the servo library, then you will need to use a different specific pin. See section
1.4.1 Supported Platforms in the IRLib users manual for a table which shows the relationship
between hardware timers and pin numbers.
Loading the Software
We presume you have already installed the IRLib library as described earlier in this tutorial. Let's
load a simple sketch and see how it works. This is the IRsendDemo sketch from the examples
folder.
In this somewhat trivial example we send the code to turn on and off a Sony DVD player every time
you type a character into the serial monitor. We create a sending object My_Sender. There is no set
up except to initialize the serial port. In the loop we check for incoming characters and if we've got
one we send the code.
The send method has three parameters: the protocol type, the data, and the number of bits.
The IRsend object we created is a generic routine that supports all seven protocols. However in this
case since we are only using one protocol we could've created the object using:
#include <IRLib.h>
IRsend My_Sender;
void setup()
{
Serial.begin(9600);
}
void loop() {
if (Serial.read() != -1) {
//send a code every time a character is received from the serial port
//Sony DVD power A8BCA
My_Sender.send(SONY,0xa8bca, 20);
}
}
© Adafruit Industries https://learn.adafruit.com/using-an-infrared-library Page 21 of 23