Friday 22 May 2015

Arduino Lesson 15 : Blinking LED on Arduino UNO with IR(TV remote)

Intro to topic :

When we talk about communicating with arduino boards there are many many possibilities either by using buttons,keypads. sensors.shields or wireless mediums. The simplest wireless medium is to use IR sensors with arduino. So here is the tutorial how to use them with arduino and use them to control other things wirelessly.

Hardware required :

  1. Arduino UNO board.
  2. IR sensor TSOP 1738
  3. Any IR transmitter or TV remote.
  4. Connecting wires/Jumper wires.
  5. PC to configure arduino board (with arduino software installed).
  6. Bread board.




Explanation to Circuit :

As i have shown you the fritzing image the IR sensor TSOP1738 has three pins out of which two pins are used to power it up from 5v and ground and the third pin whenever recieves any IR signal on it produces on TTL signal or produces on hex value related to signal incident on it. So this trick can be used to detect the hex codes related to any button of IR sender or  IR based remote like TV remote.


Whenever TV remote button is pressed the infrared signal falls upon the reciever and then decoded by it to arduino to tell it which key is being pressed. so now we can decide what action we want to take after any specific key is being pressed by using its HEX code and making a case related in our code.

Steps to follow :


  1. Connect the Circuit according to schematic image on bread board.
  2. Power up the IC by applying it the 5v and ground.
  3. Connect the 5v and groung connections correctly and make sure they are connected to right numbered pins.
  4. Once connected correctly connect arduino to PC.
  5. open up the Arduino IDE in PC and upload the following code.



Code to be uploaded :

#include <IRremote.h>
#define irPin 2
IRrecv irrecv(irPin);
decode_results results;

void setup()
{
   Serial.begin(9600);
   irrecv.enableIRIn();
}

void loop()
{
   if (irrecv.decode(&results))
      {
      Serial.print("0x");
      Serial.println(results.value, HEX);
      delay(250);
      irrecv.resume();
      }
}




Once you uploaded the Code open up your serial monitor in Arduino IDE and take any IR remote in your home and come in front of your circuit and press any button in front of it and see the  magic. As you press any key your key code will be decoded and HEX equivalent will be shown up in serial monitor. So this shows that you have used this IC correctly and these codes can be further used in different projects like automation of devices with TV remotes.

Notice down all HEX codes of your remote with every button on page to use them here.




Steps to follow :

  1. Now once you got HEX codes of your TV remote upload the following code by changing the HEX code values as according to your own Remote.





#include <IRremote.h>
#define irPin 10
IRrecv irrecv(irPin);
decode_results results;
int vcc = 12;
int gnd = 11;
int in = 10 ;
int led = 13;
int light = 4; 
void setup() {
   Serial.begin(9600);
   pinMode(vcc,OUTPUT);
   pinMode(led,OUTPUT);
   pinMode(gnd,OUTPUT);
   pinMode(in,INPUT);
   digitalWrite(vcc, HIGH);
  digitalWrite(gnd, LOW);
  digitalWrite(led, LOW);
  digitalWrite(light, LOW);// 
  
   
   irrecv.enableIRIn();
}
void loop() {
   if (irrecv.decode(&results)) {
      switch (results.value) {
         case 0xFF30CF:
            Serial.println("1");
            break;
         case 0xFF18E7:
            Serial.println("2");
            break;
         case 0xFF7A85:
            //Serial.println("POWER");
             if(digitalRead(13)==HIGH)
            {
              digitalWrite(led, LOW);// turn on the led on pin 13
              digitalWrite(light, LOW);// 
              Serial.println("LED Turned OFF");
            }
            else if(digitalRead(13)==LOW)
            {
              digitalWrite(led, HIGH);// turns off the led at pin 13
              digitalWrite(light, HIGH);// 
              Serial.println("LED Turned ON");
            }
            break;

       }
         
         
   irrecv.resume();
   }
}













  1. now once you uploaded this code change the HEX code for your tv remote so this code will work for you.
  2. every time you press the key which is associated with to turn on or off the LED on arduino board the LED will once turn on and then turns off.
  3. You can also check the status on serial monitor for more details because the Message will be displayed accordingly there that LED is turned on or Off.

If you have any more things to ask let it be in comments i will try to more explain it.

No comments:

Post a Comment