Controlling LEDs with an IR remote


In this post, I will describe how to connect your TV remote to Arduino through a simple IR sensor. 

As you may be aware, the TV remote is based on the principle of using infrared light as the medium of communication. The IR LED is connected to the end of the circuit board of the remote and emits infrared light which is sensed by the sensor placed at the receiver of the TV. In this project, we will capture the IR light signals sent by the remote and use it to control LEDs in the way we want.

The Completed Project


Materials required


  • Arduino UNO
  • USB 2.0 Cable Type A/B
  • Any TSOP IR reciever(in this project i used a TSOP1838 IR reciever)
  • LED(s)
  • IR remote (in this project we will use a TV remote, but you can also use any other IR remote)
  • Jumper wires
  • Breadboard



Downloading the IR library


  • Libraries are used to extend the Arduino environment. We need to install libraries to work with different sensors.
  • The IR library can be downloaded from https://github.com/z3t0/Arduino-IRremote.
  • Move the library to the libraries folder under the Arduino folder and rename it as IRremote.




Making the Arduino connections

The pins of the TSOP IR sensor is as follows:


  • Connect the VCC of the IR receiver to the pin labelled 5v on the Arduino.
  • Connect the ground(GND) of the IR receiver to the GND pin on the Arduino.
  • Connect the third pin (output/signal) to pin 11 on the Arduino.
  • Now connect shorter side of the LED (negative terminal) to the GND on the Arduino.
  • Connect the other pin of the LED to pin 3 on the Arduino using a 220Ω resistor.



Initial Coding

First write the following code and record the readings of the required buttons (Power, OK, Vol Up, Vol Down) on the remote used by you. We are doing this in order to enable the capture of the HEX codes corresponding to each remote button.



The code



#include <IRremote.h> 
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
  Serial.begin(9600);   
  Serial.println("Enabling IR in");// In case the interrupt driver crashes on setup, give a clue
                        // to the user what's going on.
irrecv.enableIRIn(); // Start the receiver Serial.println("Enabled IR in"); } void loop() { if (irrecv.decode(&results)) { Serial.println(results.value, HEX); irrecv.resume(); // Receive the next value } delay(100); }



Now upload the code to your Arduino board and start the serial monitor.
To start the serial monitor, select  Tools -> serial monitor in your Arduino IDE.

Now we will record the readings of different buttons on your remote. 

Recording the readings

To do this press the required buttons on your remote and you should be seeing a specific HEX code on your serial monitor. Note that each remote will give a different HEX code based on the protocol it uses. The serial monitor should look something like this:


The final code

Now that we have understand the HEX codes corresponding to each of the buttons on the remote that we want to use to control the LEDs using Arduino, we will integrate these into our final code as mentioned below.

Remember to put an "0x" in front of the recorded value
The code

#include <IRremote.h>
int RECV_PIN = 11;
int LED = 3;
int i = 127;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
  Serial.begin(9600);
  // In case the interrupt driver crashes on setup, give a clue
  // to the user what's going on.
  Serial.println("Enabling IRin");
  irrecv.enableIRIn();      // Start the receiver
  Serial.println("Enabled IRin");
  pinMode(LED , OUTPUT);
}
void loop() {
  if (irrecv.decode(&results)) {
      Serial.println(results.value, HEX);
      irrecv.resume(); // Receive the next value

} if (results.value == 0x80BF3BC4){ //reading of "power" button analogWrite(LED,i);// set LED to medium brightness } if (results.value == 0x80BF5BA4){ //"ok" button analogWrite(LED,0);//turn LED off } if (results.value == 0x80BF53AC && i < 256){ //"volume up" button i+=10; analogWrite(LED, i); //brightening the LED by a factor of 10 } if (results.value == 0x80BF4BB4 && i > 0){//volume down button i-=10; analogWrite(LED, i); //dimming LED by a factor of 10 } delay(100); }


Now that you have written your initial program, try doing the same with more LED(s) 
Happy tinkering, All the best 
Keep watching this space for more interesting projects......... 

Comments

  1. Hi Felix, well done. I guess this is meant for advanced users who alrady know something about the whole Arduino business. Can you tell me where I write the code, and how do I get it into the...well...arduino. Or maybe you can refer me to a site where lesser folks like me usually go.

    ReplyDelete
    Replies
    1. Sure im making a blog on the basics of Arduino too ..........i am hoping it will be done by today........ ill notify you when i am done

      Delete
    2. Check out : http://arduinoprojectsforbeginners.blogspot.com/2018/06/getting-started-with-arduino-uno.html

      Delete
  2. Great post. Could u pls write similar one for intel Edison

    ReplyDelete
    Replies
    1. I dont know much about Intel Edison .......sry to disappoint you...... but maybe I will post it sometime in the future if I get to it.

      Delete
  3. Hi Felix, Good post. I may need to learn the basics first. Will look forward to meet you personally and discuss.
    All the best. Will be waiting for next posts.

    ReplyDelete
    Replies
    1. Thank you !! Looking forward to meet you for the discussion.

      Delete
  4. This comment has been removed by the author.

    ReplyDelete

Post a Comment