Hello learner, in this post I want to show you how to control LED with IR remote. Here are below the components we required:
- Infrared (IR) remote and receiver
- Arduino board (I was using nano for this tutorial)
- Cable jumpers
- LEDs
- Resistor
- Breadboard
Wiring diagram:
- Blue jumper (IR receiver data) connected to pin 4 arduino), check your own IR device by referring to its datasheet
- Orange jumper (LED 1) connected to pin 2 arduino)
- Green jumper (LED 2) connected to pin 3 arduino)
- Black jumper is Ground
- Red jumper is VCC (5V)
We are going to use 2 arduino programs, first program is for acquiring your remote hexadecimal number and the second program is for testing your IR remote and receiver by controlling the LEDs
*Before uploading the program, we need IR remote library to be able to program this device with arduino, below is the download link for IR remote library. After finish downloading, copy and paste inside your C:\...\...\arduino\library
First program:
#include <IRremote.h> //IR library
int recPin = 4; //Data pin from IR receiver connected to pin 4 arduino
IRrecv recIr(recPin);
decode_results results;
void setup() {
pinMode(recPin, INPUT);
Serial.begin(9600); //Serial communication to get the hexadecimal numbers for each button
recIr.enableIRIn();
}
void loop() {
if(recIr.decode(&results)){
Serial.println(results.value, HEX);
recIr.resume();
}
}
Second program:
#include <IRremote.h> //IR library
#define button1 0xFFA25D //Button no 1 on IR remote with hexadecimal FFA25D
#define button2 0xFF629D //Button no 2 on IR remote with hexadecimal FF629D
int recPin = 4; //Data pin from IR receiver connected to pin 4 arduino
IRrecv recIr(recPin);
decode_results results;
int led1 = 2; //Led 1 connected to pin 2 arduino
int led2 = 3; //Led 2 connected to pin 3 arduino
boolean stateLed1 = 0;
boolean stateLed2 = 0;
void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(recPin, INPUT);
Serial.begin(9600);
recIr.enableIRIn();
}
void loop() {
if(recIr.decode(&results)){
Serial.println(results.value, HEX);
recIr.resume();
int hexa = results.value;
switch(hexa){
case button1:
{if(stateLed1 == 0){
digitalWrite(led1, HIGH);
stateLed1 = 1;
}
else if(stateLed1 == 1){
digitalWrite(led1, LOW);
stateLed1 = 0;
}
}
break;
case button2:{
if(stateLed2 == 0){
digitalWrite(led2, HIGH);
stateLed2 = 1;
}
else if(stateLed2 == 1){
digitalWrite(led2, LOW);
stateLed2 = 0;
}
}
break;
default:
Serial.println("waiting request... ... ...");
}
}
}
The Video how to contol LED with IR remote arduino:
If you have a queston, please let me know by put the comment below or on my youtube channel.
See you and thanks.