Controlling LED on Arduino using IR Remote

Do you know how infrared receiver works and how to use it?

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.

Photo 2019 08 23 08 59 36
Figure 1 : IR receiver connection
Photo 2019 08 23 08 59 24
Figure 2 : Hardware connection

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();
}
}
view raw IRremote.ino hosted with ❤ by GitHub

References :

  1. Using IR Remote Controls with Arduino

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.

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorial

Raspberry Pi Pico VS Arduino MKRZero
Raspberry Pi Pico VS Teensy LC
A New Challenger in MCU Platform – Raspberry Pi Pico
Raspberry Pi Pico VS Arduino UNO
Raspberry Pi Pico VS micro:bit V2
Scroll to Top