Menu Close

Infrared Tutorial on Arduino

Robo India presents tutorial on how to control Arduino using IR Receiver.

Detailed Tutorial

1. Introduction:

It is very easy to have wireless control on Arduino.

In this tutorial we will be connecting the IR receiver to the Arduino UNO, and then use a Library that was designed for this particular sensor.

2. Circuit

Make the following connections with Arduino-

3. Library File

Following library will be required to run this sketch. Download the zip file extract the same and copy this to your Arduino library folder.

This library file should be placed at the install folder of Arduino. I have a 64 bit Win7 OS and my arduino library folder address is located at

C:\Program Files (x86)\Arduino\libraries 

You may download library file from here.

4. Programming

You may download this Arduino Sketch from here.

// Robo India Tutorial 
// Code for IR Remote Sensor 
// Hardware: Arduino and IRRemote

#include <boarddefs.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>



int receiver = 2;                                 // Signal Pin of IR receiver connect with Arduino Digital Pin 11

IRrecv irrecv(receiver);                           // create instance of 'irrecv'  (Object Declaring)
decode_results results;                            // create instance of 'decode_results'

void setup()                                       // setup code runs once
{
  Serial.begin(9600);
  Serial.println("IR Receiver Button Decode"); 
  irrecv.enableIRIn();                            // Start the receiver
  
}                                                  


void loop()                                        // loop runs constantly
{
  if (irrecv.decode(&results))                     // have we received an IR signal?
    {
      translateIR(); 
      irrecv.resume();                             // receive the next value
    }  
}                                                    
                                                    
void translateIR()                                // takes action based on IR code received 
{ 
     switch(results.value)                          //Declaring IR Remote codes
     {                                
                                      
      case 0x511DBB:     Serial.println(" FORWARD");   break;
      case 0x52A3D41F:   Serial.println(" LEFT");      break;
      case 0xD7E84B1B:   Serial.println(" -OK-");      break;
      case 0x20FE4DBB:   Serial.println(" RIGHT");     break;
      case 0xFFA857:     Serial.println(" REVERSE");   break;
      case 0xC101E57B:   Serial.println(" 1");         break;
      case 0x97483BFB:   Serial.println(" 2");         break;
      case 0xF0C41643:   Serial.println(" 3");         break;
      case 0xFF30CF:     Serial.println(" 4");         break;
      case 0x3D9AE3F7:   Serial.println(" 5");         break;
      case 0xFF7A85:     Serial.println(" 6");         break;
      case 0x8C22657B:   Serial.println(" 7");         break;
      case 0x488F3CBB:   Serial.println(" 8");         break;
      case 0x449E79F:    Serial.println(" 9");         break;
      case 0x32C6FDF7:   Serial.println(" *");         break;
      case 0x1BC0157B:   Serial.println(" 0");         break;
      case 0x3EC3FC1B:   Serial.println(" #");         break;
      case 0xFFFFFFFF:    Serial.println(" REPEAT");    break;  
      default:           Serial.println(" other button");
     }
delay(50); 
} 

5. Output

After uploading the code successfully, Open up the Serial Monitor, get the remote and press the buttons. Value of button should appear on the Serial Monitor.

If you have any query please write us at support@roboindia.com

Thanks and Regards
Content Development Team 
Robo India
https://roboindia.com

Leave a Reply