Remote controls such as those used for your TV, DVD/Blu-ray or Cable box use infrared transmitters and receivers. The transmitter is basically nothing more than a flashlight that emits a light beam at a frequency that is lower than the human eye can detect.
Note that there is a lot of different types of IR receivers so be careful when giving the connections, the pin(VCC, GND, OUT) might be shuffled in the model you are using.
/*
* IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
* An IR detector/demodulator must be connected to the input RECV_PIN.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
*/
#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
// In case the interrupt driver crashes on setup, give a clue
// to the user what's going on.
Serial.println("Enabling IRin");
irrecv.enableIRIn(); // Start the receiver
Serial.println("Enabled IRin");
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
delay(100);
}
Now let’s connect an LED to one of the digital pins of Arduino and edit the above example to turn ON/OFF the LED using the IR remote.
/*
IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
An IR detector/demodulator must be connected to the input RECV_PIN.
Version 0.1 July, 2009
Copyright 2009 Ken Shirriff
http://arcfn.com
*/
#include <IRremote.h>
int RECV_PIN = 11;
int codeON = 16744575;
int codeOFF = 16711935;
int code;
int LED = 9;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
// In case the interrupt driver crashes on setup, give a clue
// to the user what's going on.
Serial.println("Enabling IRin");
irrecv.enableIRIn(); // Start the receiver
Serial.println("Enabled IRin");
pinMode(LED, OUTPUT); digitalWrite(LED, LOW);
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, DEC);
code = results.value, DEC;
irrecv.resume(); // Receive the next value
}
if (code == codeON)
digitalWrite(LED, HIGH);
else if (code == codeOFF)
digitalWrite(LED, LOW);
delay(100);
}
Tags: Home Automation, IR, Remote Control
Remote controls such as those used for your TV, DVD/Blu-ray or Cable box use infrared transmitters and receivers. The transmitter is basically nothing more than a flashlight that emits a light beam at a frequency that is lower than the human eye can detect.
Note that there is a lot of different types of IR receivers so be careful when giving the connections, the pin(VCC, GND, OUT) might be shuffled in the model you are using.
/*
* IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
* An IR detector/demodulator must be connected to the input RECV_PIN.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
*/
#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
// In case the interrupt driver crashes on setup, give a clue
// to the user what's going on.
Serial.println("Enabling IRin");
irrecv.enableIRIn(); // Start the receiver
Serial.println("Enabled IRin");
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
delay(100);
}
Now let’s connect an LED to one of the digital pins of Arduino and edit the above example to turn ON/OFF the LED using the IR remote.
/*
IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
An IR detector/demodulator must be connected to the input RECV_PIN.
Version 0.1 July, 2009
Copyright 2009 Ken Shirriff
http://arcfn.com
*/
#include <IRremote.h>
int RECV_PIN = 11;
int codeON = 16744575;
int codeOFF = 16711935;
int code;
int LED = 9;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
// In case the interrupt driver crashes on setup, give a clue
// to the user what's going on.
Serial.println("Enabling IRin");
irrecv.enableIRIn(); // Start the receiver
Serial.println("Enabled IRin");
pinMode(LED, OUTPUT); digitalWrite(LED, LOW);
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, DEC);
code = results.value, DEC;
irrecv.resume(); // Receive the next value
}
if (code == codeON)
digitalWrite(LED, HIGH);
else if (code == codeOFF)
digitalWrite(LED, LOW);
delay(100);
}
Tags: Home Automation, IR, Remote Control