This afternoon, I've made a project on my Arduino Uno. It is programmed to light a LED for each button I pressed on a remote control. I've used :
Arduino Uno |
IR Receiver |
10K Ohm Resistors |
Phillips Remote Control |
IRremote library download link >>>>>> HERE
#include <IRremote.h> // use the library
int receiver = 8; // pin 1 of IR receiver to Arduino digital pin 8
IRrecv irrecv(receiver); // create instance of 'irrecv'
decode_results results;
int led1=2;
int led2=3;
int led3=4;
void setup()
{
Serial.begin(9600); // for serial monitor output
irrecv.enableIRIn(); // Start the receiver
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
}
void loop()
{
if (irrecv.decode(&results)) // have we received an IR signal?
{
Serial.println(results.value, HEX); // display it on serial monitor in hexadecimal
irrecv.resume(); // receive the next value
} // Your loop can do other things while waiting for an IR command
//below is triggering mode
//0x???? ????is the HEX code detected, must add 0x to trigger something
switch(results.value){
case 0x458: //1st push (UP Button Phillips)
digitalWrite(led1,HIGH);
break;
case 0x10458: //2nd push
digitalWrite(led1,HIGH);
break;
case 0x45A: //1st push (LEFT Button Phillips)
digitalWrite(led2,HIGH);
break;
case 0x1045A: //2nd push
digitalWrite(led2,HIGH);
break;
case 0x45B: //1st push (RIGHT Button Phillips)
digitalWrite(led3,HIGH);
break;
case 0x1045B: //2nd push
digitalWrite(led3,HIGH);
break;
case 0x45C: //1st push (OK Button Phillips)
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
break;
case 0x1045C: //2nd push
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
break;
case 0x459: //1st push (DOWN Button Phillips)
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH);
digitalWrite(led3,HIGH);
break;
case 0x10459: //2nd push
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH);
digitalWrite(led3,HIGH);
break;
}
}
Wanna know how it works? Watch the video below!!!! Enjoy!
by Weng Fei