$USD
  • EUR€
  • £GBP
  • $USD
PROJECTS Arduino

Arduino Project 14: IR Remote Controlled LED

DFRobot Jun 13 2017 2611

Related Product: Beginner Kit for Arduino

IR Remote Controlled LED

In this arduino project, we will teach you how IR Remote Controlled LED . 

An infrared receiver, or IR receiver, is hardware device that sends information from an infrared remote control to another device by receiving and decoding signals. In general, the receiver outputs a code to uniquely identify the infrared signal that it receives. This code is then used in order to convert signals from the remote control into a format that can be understood by the other device. Because infrared is light, it requires line-of-sight visibility for the best possible operation, but can however still be reflected by items such as glass and walls. Poorly placed IR receivers can result in what is called "tunnel vision", where the operational range of a remote control is reduced because they are set so far back into the chassis of a device.


Warm-up Experiment:
Components

DFRduino UNO R3 (samilar as Arduino UNO R3)*1
Prototype Shield *1
Jumper Cables M/M *3
IR Receiver *1
IR Remote Controller*1

From Arduino Starter Kit


Wiring

Note that the “V-out” lead of the infrared receiver must be connected to Digital Pin 11 on the Arduino.

Fig. 14-1 IR Receiver Diagram

Code

We need to invoke the “IRremote” library first. Unzip the RAR and save it to the file Arduino libraries directory. Run “IRrecvDemo” in the example.
If you don’t know how to invoke a library in the Arduino IDE, refer back to the exercise in arduino Project 5.


This sketch is from “IRrecvDemo” in the examples of the “IRremote” library.
Sample code 14-1:
//project fourteen – infrared receiving tube
#include <IRremote.h>                   // insert IRremote.h library
int RECV_PIN = 11;                           //define the pin of RECV_PIN 11
IRrecv irrecv(RECV_PIN);                 //define RECV_PIN as infrared receiver
decode_results results;                  //define variable results to save the result of infrared
receiver


void setup(){
Serial.begin(9600);                        // configure the baud rate 9600
irrecv.enableIRIn();                      //Boot infrared decoding
}


void loop() {
//test if receive decoding data and save it to variable results
if (irrecv.decode(&results)) {
// print data received in a hexadecimal
Serial.println(results.value, HEX);
irrecv.resume(); //wait for the next signal
}
}


After uploading the code, open the serial monitor of the Arduino IDE and configure the baud rate 9600 in line with Serial.begin(9600).


After configuration, press the button on the remote controller towards the infrared receiver. Each button has a hexadecimal code. We can see the code on serial monitor no matter which button we press. For example, we press button “0”, the hexadecimal code received is FD30CF.


If you keep pressing one button, the serial monitor reads “FFFFFFFF”.


If it is received properly in the serial port, the code should be six digits starting with FD. If the controller does not send out the signal towards the infrared receiver, it might receive wrong code as we can see below.

The original infrared decoding is too complicated to manipulate, which is why we use the library that is built by others without completely understanding it. Since we have got the idea of decoding for infrared signal, let’s make an infrared controlled LED.



Remote Control LED

Component

DFRduino UNO*3
Prototype Shield*1
Jumber Cables M/M*3
IR Receiver *1
IR Remote controller*1
5MM LED*1Resistor 220R*1

Wiring

Based on the previous circuit, add an LED and a resistor. Connect the LED to digital pin 10 and the signal LED of infrared receiver to digital pin 11.

Fig. 14-2 IR Remote Controlled LED Circuit Diagram

Code

Sample Code 14-2:
#include <IRremote.h>
int RECV_PIN = 11;
int ledPin = 10;                                                   // LED – digital 10
boolean ledState = LOW;                                 // ledState to store the state of LED
IRrecv irrecv(RECV_PIN);decode_results results;

void setup(){
Serial.begin(9600);
irrecv.enableIRIn();
pinMode(ledPin,OUTPUT);                            // define LED as output signal
}


void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);


//once receive code from power button, the state of LED is changed from HIGH
to LOW or from LOW to HIGH.


if(results.value == 0xFD00FF){
ledState = !ledState;                                    //reverse
digitalWrite(ledPin,ledState);                     //change the state of LED
}
irrecv.resume();
}
}


Code

Defining the infrared receiver is the same as the last sketch.

#include <IRremote.h> //insert IRremote.h library
int RECV_PIN = 11; //define the pin of
RECV_PIN 11
IRrecv irrecv(RECV_PIN); //define RECV_PIN as infrared
receiver
decode_results results; //define variable results to
save the result of infrared receiver
int ledPin = 10; //LED – digital 10
boolean ledState = LOW; //Ledstate used to store the
LED status


In the setup() function, we use serial port to boot the infrared decoding and configure pinMode of digital pins. In the main program,
we test if receive infrared signal and store data in the results variable.


if (irrecv.decode(&results))
Once the Arduino receives data, the program does two things: first it tests whether infrared code is received from the power button.


if(results.value == 0xFD00FF)
The second thing is to make the LED change state.


ledState = !ledState; //Flip
digitalWrite(ledPin,ledState); //Change corresponding LED status


You might not be so familiar with “!”. “!” is a logical NOT.
ledState' is the opposite state of 'ledState' “!” is only used in the variable that
only holds 2 states, or boolean type of variable.


Next, the Arduino will wait for the next signal
irrecv.resume();


Exercise

1. Combine the fan project with the current project. Add one more function to the mini controller to control a LED and a fan.
2. Make a DIY a remote controlled project, e.g.: a small figure that can move with servos controlled by infrared signals.

Related category: arduino kits > education kits

Last Arduino Tutorial 13: DIY Fan

REVIEW