light_irsend.jpg

Hardware Issues

IRLib not only receives and decodes IR signals only it tin transmit them likewise using an IR LED and a commuter circuit. The library has been used to control TVs, cable boxes, DVDs, VCRs, and IR controlled toys such as helicopters and dinosaur robots.

It could also be used to control some home automation devices. Some users have attempted to control air conditioners and fans even so protocols used for air-conditioners are extremely hard to implement and nosotros take not directly supported such protocols considering they are very rare.

Typically the output pin of an Arduino cannot supply sufficient electric current to drive and IR LED and so you will want to implement a simple driver excursion using NPN transistor and a 470 ohm resistor is shown here:

light_ir_output.png

Brand sure that y'all get the polarity of the LED correct. The shorter of the two leads connects to the transistor and the longer one connects to the positive supply. Notation that the current passing through the LED will in all likelihood volition exceed the maximum continuous current rating. Nevertheless because the indicate is modulated and sending a sequence of pulses that will merely last a few milliseconds the circuit will work fine.

More than advanced driver circuit schematics are bachelor in the IRLib transmission in section 1.4 Hardware Considerations.

While we can connect an IR receiver to any available digital input pivot, you can just utilize 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 pivot 9 for the Leonardo and Mega. If you lot have modified the library to utilise a different timer such as changing the timer number on a Leonardo to avert conflicts with the servo library, then you lot will need to use a different specific pin. See department one.4.i Supported Platforms in the IRLib users manual for a table which shows the relationship between hardware timers and pin numbers.

Loading the Software

We assume you have already installed the IRLib library as described earlier in this tutorial. Let'south load a unproblematic sketch and see how it works. This is the IRsendDemo sketch from the examples folder.

#include <IRLibAll.h>  IRsend mySender;  void setup() {   Series.begin(9600); }  void loop() {   if (Serial.read() != -i) {     //send a code every time a character is received from the serial port     //Sony DVD power A8BCA     mySender.transport(SONY,0xa8bca, twenty);   } }
#include <IRLibAll.h>  IRsend mySender;  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     mySender.ship(SONY,0xa8bca, 20);   } }

In this somewhat trivial example we transport the code to turn on and off a Sony DVD player every time you type a grapheme into the serial monitor. We create a sending object mySender. At that place is no set except to initialize the serial port. In the loop we bank check for incoming characters and if we've got one we send the code.

The send method has three parameters: the protocol blazon, the information, and the number of $.25.

The IRsend object we created is a generic routine that supports all 11 supported protocols. Notwithstanding in this case since we are simply using i protocol we could've created the object using:

IRsendSony mySender;
IRsendSony mySender;

Within the loop the send control would and so be:

mySender.send(0xa8bca, xx);
mySender.ship(0xa8bca, 20);

Some protocols such as NEC ever utilize the same number of bits and then you do not need to specify every bit an additional parameter. See the the users manual to see if the extra $.25 parameter is required.

The users manual too gives you information almost how to create decoding and sending routines that only use a specific subset of the supported protocols. This is much easier to do in IRLib two.0 than it was in the original version.

Sending and Receiving in the Aforementioned Programme

At that place are special considerations when doing sending and receiving in the same plan. Both sending and receiving brand use of the building hardware timers. However the timer is used for two different purposes. When y'all send a code, information technology reconfigures the timer and disables receiving. So you have to reenable your receiver after each send. For case:

mySender.transport(Protocol, Data, Bits); myReceiver.enableIRIn(); // Re-enable receiver
mySender.send(Protocol, Information, Bits); myReceiver.enableIRIn(); // Re-enable receiver

Normally you would only demand to telephone call  myReceiver.enableIRIn();  once in the setup routine simply if you are both sending and receiving you have to call it after each ship.

For a complete example of how to send and receive in the aforementioned program, look at the record.ino sample sketch in the "IRLib2/examples" folder.  When you load the sketch, open your series monitor, betoken a remote at the receiver and push a button. The programme will capture that lawmaking. Then every time the type of grapheme into the serial monitor it volition repeat that lawmaking through the LED.

light_irrecord.jpg

In a separate tutorial we will prove you how to utilize IRLib to create your own universal remote by either sending information through the serial port into the Arduino or by creating a spider web-based universal remote using Arduino Yun.

All photos, videos and wiring courtesy Kenneth Young

This guide was start published on Feb 26, 2015. It was last updated on Feb 26, 2015.

This page (Sending IR Codes) was final updated on Mar 15, 2022.

Text editor powered past tinymce.