Menu Close

LED Control with Infrared – Arduino

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

1. Introduction:

It is very easy to have wireless control on Arduino.

In this tutorial we will be control the LEDs connected to Arduino UNO using IR Remote.

2. Required Hardware

Following Hardware will be required to perform this circuit.

S.No.ItemQuantity
1 Arduino UNO 1
2 Breadboard 1
3 IR Remote 1
4 LED 3
5 Resistor 1k 3
6 Male to Female Jumper 3
7 Male to Male Jumper 8

3. Building Circuit

Make the following connections with Arduino-

4. 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.

5. Programming

You may download this Arduino Sketch from here.

//Robo India tutorial to control LEDs using IR Remote
//https://www.roboindia.com/tutorials

#include <boarddefs.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>
 
int IR_Remote = 8;  //IR Sensor connected with arduino 
int RedLED = 4;
int GreenLED = 3;
int YellowLED = 2;
int led[] = {0,0,0,0};

#define code1  0xC101E57B  // Hex Code for Button 1 of IRR Remote
#define code2  0x97483BFB  // Hex Code for Button 2 of IRR Remote
#define code3  0xF0C41643  // Hex Code for Button 3 of IRR Remote
 
IRrecv irrecv(IR_Remote);
 
decode_results results;
 
void setup()
{
  irrecv.enableIRIn();  // Start the receiver
  pinMode(RedLED, OUTPUT);
  pinMode(GreenLED, OUTPUT);
  pinMode(YellowLED, OUTPUT);
}
 
void loop() {
  if (irrecv.decode(&results)) 
  {
    unsigned int value = results.value;
    switch(value) 
      {
       case code1:
         if(led[1] == 1) 
         {        
            digitalWrite(RedLED, LOW);   //led off when button is pressed
            led[1] = 0;                 
         } 
         else 
         {                                // if first led is off
             digitalWrite(RedLED, HIGH); // turn it on when the button is pressed
             led[1] = 1;                 // and set its state as on
         }
       break; 
      
       case code2:
         if(led[2] == 1) 
         {        
            digitalWrite(GreenLED, LOW);   
            led[2] = 0;                 
         } 
         else 
         {                      
             digitalWrite(GreenLED, HIGH); 
             led[2] = 1;          
         }
       break; 
       
       case code3:
         if(led[3] == 1) 
         {
            digitalWrite(YellowLED, LOW);
            led[3] = 0;
         } else 
         {
             digitalWrite(YellowLED, HIGH);
             led[3] = 1;
         }
          break;          
    }
  irrecv.resume(); // Receive the next value
  }
}


6. Output

After uploading the code successfully, If you press button 1 on IR Remote red LED will glow, and if you press same button again red LED will turn off. Same as for Green and Yellow LED for button 2 and 3 of IR Remote respectively.

You can add more led for more buttons.

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