Nicholas_N
Published

Control an LED with the Remote Control

Receive the signal and control an LED.

BeginnerShowcase (no instructions)12,274
Control an LED with the Remote Control

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
LED (generic)
LED (generic)
×1
Infrared Receiver
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

circuit diagram

Code

Project code

Arduino
#include <IRremote.h>


const int receiver = 11; 
const int led = 9;

IRrecv ir_receiver(receiver);           
decode_results results;          

void setup()   
{
  Serial.begin(9600);
  ir_receiver.enableIRIn(); 
  pinMode(led, OUTPUT);  
}


void loop() 
{
  if (ir_receiver.decode(&results))

  {
    Serial.println(results.value, HEX);
    translateIR(); 
    ir_receiver.resume(); 
    delay(200); 
  } 
  
}

void translateIR() 

{
  int sensorValue=0;
  sensorValue = digitalRead(led);
  
  switch(results.value){

  case 0x20DF10EF:
    if (sensorValue==0){
      
      Serial.println(" ON "); 
      digitalWrite(led, HIGH); 
      break;
    }
    if (sensorValue==1){
      
      Serial.println(" OFF "); 
      digitalWrite(led, LOW); 
      break;
    }
    
    case 0x20DFD02F:
    if (sensorValue==0){
      Serial.println(" BLINK ");
      for(int i=1;i<5;i++){
      digitalWrite(led, HIGH);
      delay(500);
      digitalWrite(led, LOW);
      delay(500);
      }
      break;
  }
  default: 
    Serial.println(" other button   ");
  }
}

Infrared Receiver Code

Arduino
#include <IRremote.h>

const int receiver=11;

IRrecv ir_receiver(receiver);
decode_results results;

void setup() {
 Serial.begin(9600);
 ir_receiver.enableIRIn();
}

void dump(const decode_results* results) {
  const int protocol=results->decode_type;
  Serial.print("Protocol: ");
  if (protocol==UNKNOWN){
    Serial.println("not recognized.");
    } 
    else{
      if(protocol==NEC){
        Serial.println("NEC");
        }
      else if(protocol==SONY){
        Serial.println("SONY");
        }
      else if(protocol==RC5){
        Serial.println("RC5");
        } else if(protocol==RC6){
            Serial.println("RC6");
            }
Serial.print("Value: ");
Serial.print(results->value, HEX);
Serial.print("(");
Serial.print(results->bits, DEC);
Serial.print(" bits)");
}
}

void loop() {
 if(ir_receiver.decode(&results)) {
   dump(&results);
   ir_receiver.resume();
   }
}

Credits

Nicholas_N

Nicholas_N

0 projects • 10 followers

Comments