Trybotics Logo

Control an LED with the Remote Control

DESCRIPTION

First of all you need to know the control codes of your remote control.

Connect only the IR sensor and run his code. Open the Serial Monitor and point the remote control to the receiver. Press the buttons and the respective codes will appear. Sometimes the code 0xffffffff can appear because you have pressed the button for too long.

Then connect the LED and run the code, where you have to insert the codes of the two buttons you want to use.

With a button you can turn on and off the LED. With the other one you can make the LED blink.

Description:

Description:

First of all you need to know the control codes of your remote control.

Connect only the IR sensor and run his code. Open the Serial Monitor and point the remote control to the receiver. Press the buttons and the respective codes will appear. Sometimes the code 0xffffffff can appear because you have pressed the button for too long.

Then connect the LED and run the code, where you have to insert the codes of the two buttons you want to use.

With a button you can turn on and off the LED. With the other one you can make the LED blink.

Description:

Project codeArduino
#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 CodeArduino
#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();
   }
}

Description:

circuit diagram
Ir led bb ds8betbova


YOU MIGHT ALSO LIKE