Introduction
Infrared receiver, or IR receiver, is a device that receives and decodes infrared signal. When an infrared remote control is used on the IR receiver, the device will translate the signal and then transmit the information to other devices.
Video
This video will show you how to control LEDs using IR remote on Arduino.
Hardware Preparation
This is the hardware connection and the components needed.


Sample Code
// Include IR Remote Library by Ken Shirriff | |
#include <IRremote.h> | |
// Define sensor pin | |
const int RECV_PIN = 4; | |
// Define LED pin | |
#define RED 8 | |
#define GREEN 9 | |
#define YELLOW 10 | |
#define BLUE 11 | |
// Define integer to remember toggle state | |
int redState = 0; | |
int greenState = 0; | |
int yellowState = 0; | |
int blueState = 0; | |
// Define IR Receiver and Results Objects | |
IRrecv irrecv(RECV_PIN); | |
decode_results results; | |
void setup() { | |
// Enable the IR Receiver | |
irrecv.enableIRIn(); | |
// Set LED pins as Outputs | |
pinMode(RED, OUTPUT); | |
pinMode(GREEN, OUTPUT); | |
pinMode(YELLOW, OUTPUT); | |
pinMode(BLUE, OUTPUT); | |
} | |
void loop() { | |
if (irrecv.decode(&results)) { | |
switch (results.value) { | |
case 0xCD3221DE: | |
if (redState == 0) { | |
digitalWrite(RED, HIGH); | |
redState = 1; | |
} | |
else { | |
digitalWrite(RED, LOW); | |
redState = 0; | |
} | |
break; | |
case 0xCD32916E: | |
if (greenState == 0) { | |
digitalWrite(GREEN, HIGH); | |
greenState = 1; | |
} | |
else { | |
digitalWrite(GREEN, LOW); | |
greenState = 0; | |
} | |
break; | |
case 0xCD329B64: | |
if (yellowState == 0) { | |
digitalWrite(YELLOW, HIGH); | |
yellowState = 1; | |
} | |
else { | |
digitalWrite(YELLOW, LOW); | |
yellowState = 0; | |
} | |
break; | |
case 0xCD326996: | |
if (blueState == 0) { | |
digitalWrite(BLUE, HIGH); | |
blueState = 1; | |
} | |
else { | |
digitalWrite(BLUE, LOW); | |
blueState = 0; | |
} | |
break; | |
} | |
irrecv.resume(); | |
} | |
} | |
References :
Thank you
Thank you for reading this tutorial and we hope it helps your project development. If you have any technical inquiry, please post at Cytron Technical Forum.