ElectroPeak
Published © GPL3+

Use an IR Remote Transmitter and Receiver with Arduino

You’ll learn about IR protocol and how to use the IR receiver module.

IntermediateProtip2 hours295,647
Use an IR Remote Transmitter and Receiver with Arduino

Things used in this project

Hardware components

Arduino UNO R3
×1
Arduino Micro
×1
ElectroPeak RGB LED
×1
ElectroPeak IR Remote and IR sensor
×1
ElectroPeak Jumpers
×1

Software apps and online services

Arduino IDE

Story

Read more

Code

code 1

Arduino
/*  

 *  IR read codes 

 *  by Hanie kiani 

 *  https://electropeak.com/learn/    

 */ 

#include <IRremote.h>  //including infrared remote header file 

int RECV_PIN = 7; // the pin where you connect the output pin of IR sensor 

IRrecv irrecv(RECV_PIN); 

decode_results results; 

void setup() 

{ 

Serial.begin(9600); 

irrecv.enableIRIn(); 

{ 

void loop() 

{ 

if (irrecv.decode(&results))// Returns 0 if no data ready, 1 if data ready. 

 { 

  int results.value = results;// Results of decoding are stored in result.value 

  Serial.println(" "); 

  Serial.print("Code: "); 

  Serial.println(results.value); //prints the value a a button press 

  Serial.println(" "); 

  irrecv.resume(); // Restart the ISR state machine and Receive the next value 

}

code 2

Arduino
/*  

 *  IR read codes 

 *  by Hanie kiani 

 *  https://electropeak.com/learn/    

 */ 

#include <IRremote.h> 

 

 int RECV_PIN =6; 

 int bluePin = 11; 

 int greenPin = 10;    

 int redPin = 9; 

IRrecv irrecv(RECV_PIN); 

decode_results results; 

 

void setup(){ 

  Serial.begin(9600); 

  irrecv.enableIRIn(); 

  pinMode(redPin, OUTPUT); 

  pinMode(greenPin, OUTPUT); 

    pinMode(bluePin, OUTPUT); 

} 

 

void loop(){ 

    if (irrecv.decode(&results)){ 

int value = results.value; 

Serial.println(value);  

        switch(value){ 

          case 12495: //Keypad button "1" 

          //set color red 

          analogWrite(redPin, 0xFF); 

          analogWrite(greenPin,0x08); 

          analogWrite(bluePin, 0xFB); 

          } 

 

        switch(value){ 

          case -7177: //Keypad button "2" 

          //set color skyblue 

          analogWrite(redPin, 0x00); 

          analogWrite(greenPin,0xFF); 

          analogWrite(bluePin, 0xFF); 

          } 

          switch(value){ 

          case 539: //Keypad button "3" 

           //set color pink 

          analogWrite(redPin, 0x1F); 

          analogWrite(greenPin,0x00); 

          analogWrite(bluePin, 0x8F); 

          } 

          switch(value){ 

          case 25979: //Keypad button "4" 

          //set color light green 

          analogWrite(redPin, 0x11); 

          analogWrite(greenPin,0x5F); 

          analogWrite(bluePin, 0x01); 

          } 

 

        irrecv.resume();  

    } 

}

code 3

Arduino
/*  

 *  IR REMOTE CONTROL + RGB 

 *  by Hanie Kiani 

 *  https://electropeak.com/learn/    

 */ 

 

#include <IRremote.h> 

#include  <Keyboard.h>

 

 

int RECV_PIN = 11; 

IRrecv irrecv(RECV_PIN); 

decode_results results; 

 

void setup() 

{ 

  Serial.begin(9600); 

  irrecv.enableIRIn(); // Start the receiver 

  Keyboard.begin(); 

} 

 

void loop() { 

  if (irrecv.decode(&results))  

  {  int value = results.value; 

Serial.println(value);          

      switch(value) 

      { 

         

        //Backward key is used for left key operation                  

        case 8925:  Keyboard.press(KEY_LEFT_ARROW); //left key 

                         delay(100); 

                         Keyboard.releaseAll(); 

                         break; 

        //Forward Key is used for right key operation 

        case 765:  Keyboard.press(KEY_RIGHT_ARROW); //right  key 

                         delay(100); 

                         Keyboard.releaseAll(); 

       //Play Key is used for up key operation 

        case -15811:  Keyboard.press(KEY_UP_ARROW); //up  key 

                         delay(100); 

                         Keyboard.releaseAll(); 

                         break;                         

      }   

    irrecv.resume(); // Receive the next value 

  } 

}

Credits

ElectroPeak

ElectroPeak

57 projects • 731 followers
At ElectroPeak we want to teach you to enjoy electronics more. We offer Top-notch guides and worry-free shopping experience.

Comments