Wednesday, November 25, 2015

USING TV REMOTE WITH ARDUINO TO CONTROL RGB LED

INTRODUCTION

Infrared remote control project is one of the popular projects for arduino lovers. We are here talking about the tv remote. There are various button of tv remote that are not used. Also if we can make this tv remote to control things other than tv than this will be cool and great.
WANT TO LEARN ABOUT ARDUINO AND ARDUINO BASED PROJECT,CLICK HERE..
Arduino is an open source development board which is very good research and learning platform for technical and non technical person. It is very easy and comfortable to use in most of the situation from school project to the professional job. So it gives us knowledge about electronics and help develop idea of all age students. Learning arduino is awesome with enough hardware.
 Infrared remote works on 38khz. Here I used a chinese cheap remote. 

Components required

1. computer or laptop
2. arduino (uno)
3. tv remote
4. IR receiver
5. some jumpers
6. Breadboard



Circuit diagram

connect your components as shown in the diagram below with the help of bread board carefully. 

IR receiver is a three pin device and it has internal op-amp and decoder. It receives the binary signal of IR transmitted from the remote of tv and sends it to the pin 11 of the arduino. 

Installing arduino library

  1. download the arduino IRremote library by clicking here.
  2. copy the folder of IRremote to the following directory.
            C:\Program Files (x86)\Arduino\libraries
     3. Remove the library folder named as RobotIRremote from the above directory
     4. Then restart your arduino IDE if you already opened it. 
IRremote library installation complete. 

Code of the project

Test code

  1. copy and paste the following code to your arduino IDE. 
  2. upload the code into the arduino
  3. open serial monitor 
  4. click remote whose IR led is heading to the IR receiver with the arduino.
  5. note the hex value that is shown in the serial monitor. 
in my case when i pressed power and set button of remote and pressed 100 (password of remote) , then the value shown are like 
pressing 1  showed 1 again pressing 801
pressing 2 showed 2 again pressing 802 
and so on. 

#include <IRremote.h>
int RECV_PIN = 11;      
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn();
}

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


Controlling rgb led

connect your rgb led as described
  • red to pin 13
  • green to pin 10
  • blue to pin 9 of arduino

Code for RGB led controlling

copy and paste the following code to your arduino IDE and upload it to your arduino. press your remote key from 1 again 1 then 2 again 2 ,  3 again 3 and so on upto 7. various types of color can be achieved. 

#include <IRremote.h>
int ir = 11;
int red=13;
int green=10;
int blue=9;
IRrecv irrecv(ir);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  pinMode(red,OUTPUT);
  pinMode(green,OUTPUT);
  pinMode(blue,OUTPUT);
}

void loop()
{
  if (irrecv.decode(&results))
    {
     Serial.println(results.value, HEX);
    if(results.value==1)
    {
    digitalWrite(red,HIGH);
    digitalWrite(green,LOW);
    digitalWrite(blue,LOW);
    }
  else if(results.value==2)
  {
    digitalWrite(red,LOW);
    digitalWrite(green,HIGH);
    digitalWrite(blue,LOW);
  }
  else if(results.value==3)
  {
    digitalWrite(red,LOW);
    digitalWrite(green,LOW);
    digitalWrite(blue,HIGH);
  }
  else if(results.value==4)
  {
    digitalWrite(red,HIGH);
    digitalWrite(green,HIGH);
    digitalWrite(blue,LOW);
  }
  else if(results.value==5)
  {
    digitalWrite(red,HIGH);
    digitalWrite(green,LOW);
    digitalWrite(blue,HIGH);
  }
  else if(results.value==6)
  {
    digitalWrite(red,LOW);
    digitalWrite(green,HIGH);
    digitalWrite(blue,HIGH);
  }
  else if(results.value==7)
  {
    digitalWrite(red,HIGH);
    digitalWrite(green,HIGH);
    digitalWrite(blue,HIGH);
  }
  else
  {
    digitalWrite(red,LOW);
    digitalWrite(green,LOW);
    digitalWrite(blue,LOW);
  }
irrecv.resume(); // Receive the next value
    }
}

Possible problems

Every type of remote do not give simple number after decoding like 1, 2, 3 etc instead they give long hex code. This can not be directly used in if-else statement. So there is a method of placing 0x in front of the hex code in if else statement.
so try the following code after you run the test code given above and either copy paste or modify the test code.



#include <IRremote.h>
int before;
int RECV_PIN = 11;   
int led=13;      
IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  before=0;
  pinMode(led, OUTPUT);      // sets the digital pin as output
 }

void loop() 
{
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
  if(results.value==0xyour hex code)  // for example   0xFF52AD
  {
    if(before==0)
    {
       digitalWrite(led,HIGH);
       before=1;
    }
  }
  else
  {
    digitalWrite(led,LOW);
    before=0;
  }
}





first open serial monitor to veiw the decoded hex code and use hex code in if else condition as guided above.

note that in this section where 'your hex code' is written there copy the code of your code shown in serial monitor of your arduino IDE. 


comment for your queries and share the post so that other can view it. if i have done mistake please kindly make me known about that.. 
thanks for viewing the post...............


No comments:

Post a Comment