Skip to main content

IR Remote

Using a Remote Control with Arduino

Code and circuits to implement remote control.

Tutorial is here: IR Remote circuits and code you may also need to get the library from gitHub IRremote library zip download

Example Code to Get Started



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

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

}

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

Project Code


const int red = 8;
const int yellow = 9;
const int green = 10;
const int RECV_PIN = 7;
//IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
  Serial.begin(9600);
  IrReceiver.begin(RECV_PIN, DISABLE_LED_FEEDBACK);
  IrReceiver.enableIRIn();
  //  irrecv.blink13(true);
}
void ledLights(bool r, bool y, bool g)
{
  digitalWrite(red, r);
  digitalWrite(yellow, y);
  digitalWrite(green, g);
}
void loop() {
  if (IrReceiver.decode()) {
    Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX);
    switch (IrReceiver.decodedIRData.decodedRawData) {
      case 0xF30CFF00:
        Serial.println("red");
ledLights(1,0,0);
        break ;              case 0xE718FF00:
        Serial.println("yellow");
ledLights(0,1,0);
        break ;
              case 0xA15EFF00:
        Serial.println("green");
ledLights(0,0,1);
        break ;
    }

    IrReceiver.resume();
  }
}

You can copy and paste this into the arduino IDE. You will need to include the IRremote.h library