적외선 리모컨은 일상생활에서 자주 사용하고 있는 전자제품이다. TV를 켜고 끄거나 채널을 바꿀 때 사용하는 리모컨도 적외선 리모컨이고 가정에서 사용하는 에어컨이나 다른 전자 기기를 제어할 때도 적외선 리모컨을 사용하고 있다. 적외선 리모컨은 전자기파를 이용하며 제품마다 고유의 값으로 통신하고 있어 중복되지 않게 사용할 수 있다. 적외선은 사람 눈에 보이지 않으나 적외선을 발생할 때 LED를 켜서 눈으로 보이는 것 처럼 만들수 있다.
적외선 통신의 특징은 근거리 통신용이며 주파수는 38KHz를 사용한다는 것이다. 적외선 리모컨은 적외선 신호를 만들어 내는 발광 다이오드와 적외선 신호를 받아들이는 수광 다이오드가 한 쌍으로 작동한다.
[스케치] - [라이브러리 포함] - [라이브러리 관리]
'irremote' 을 검색 'IRremote by shirriff' 라이브러리 설치
[파일] - [예제] - [IRremote] - [IRrecvDemo]
/*
* 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);
}
#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
irrecv.decode(&results)
Serial.println(results.value, HEX);
/*
* 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");
pinMode(5,OUTPUT);
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
if(results.value == 0xFF30CF) digitalWrite(5,HIGH);
if(results.value == 0xFF18E7) digitalWrite(5,LOW);
}
}
pinMode(5,OUTPUT);
if(results.value == 0xFF30CF)