Week 12 – Remote Control

Arduino
Introduction – Infrared Remote Control


WHAT IS INFRARED?
Infrared radiation is a form of light similar to the light we see all around us. The only difference between IR light and visible light is the frequency and wavelength. Infrared radiation lies outside the range of visible light, so humans can’t see it:

HOW IR REMOTES AND RECEIVERS WORK?
A typical infrared communication system requires an IR transmitter and an IR receiver. The transmitter looks just like a standard LED, except it produces light in the IR spectrum instead of the visible spectrum. If you have a look at the front of a TV remote, you’ll see the IR transmitter LED:

The IR receiver is a photodiode and pre-amplifier that converts the IR light into an electrical signal. IR receiver diodes typically look like this:

HOW TO CONNECT AN IR RECEIVER TO THE ARDUINO

There are several different types of IR receivers, some are stand-alone, and some are mounted on a breakout board. Check the datasheet for your particular IR receiver since the pins might be arranged differently than the HX1838 IR receiver and remote set I am using here. However, all IR receivers will have three pins: signal, ground, and Vcc.
Lets get started with the hardware connections. The pin layout on most breakout boards looks like this:

PROGRAMMING THE IR RECEIVER

Once you have the receiver connected, we can install the Arduino library and start programming. In the examples below, I’ll show you how to find the codes sent by your remote, how to find the IR protocol used by your remote, how to print key presses to the serial monitor or an LCD, and finally, how to control the Arduino’s output pins with a remote.


INSTALL THE IRREMOTE LIBRARY

We’ll be using the IRremote library for all of the code examples below. You can download a ZIP file of the library from here.
http://z3t0.github.io/Arduino-IRremote/
To install the library from the ZIP file, open up the Arduino IDE, then go to Sketch > Include Library > Add .ZIP Library, then select the IRremote ZIP file that you downloaded from the link above.

Program1 :

#include<IRemote.h>

const int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup(){
Serial.begin(9600);
irrecv.enableIRIn();
irrecv.blink13(true);
}

void loop(){
if (irrecv.decode(&results)){
Serial.println(results.value, HEX);
irrecv.resume();
}
}

Program2 :

IR Remote control Code

#include<IRremote.h>

const int irReceiverPin = 7;
IRrecv irrecv(irReceiverPin);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
pinMode (8,OUTPUT);
pinMode (9,OUTPUT);
pinMode (10,OUTPUT);
pinMode (11,OUTPUT);
pinMode (12,OUTPUT);
}
void loop()
{
if (irrecv.decode(&results))
{
Serial.print(“IR_Code: “);
Serial.print(results.value);
irrecv.resume();
}
}