Introduction: CONTROL TV FROM LAPTOP(ARDUINO-PROCESSING SERIAL COMMUNICATION)

Hello friends!

In this instructable I will be showing you how to control your TV from your laptop.Before we begin I want you to know that that this instructable is applicable to any device which uses a remote control...

In this project we will using Processing which if you don't have downloaded on your comp you can download it from processing.org.

We will be doing serial communication betweeen Processing and arduino.This is how it works-

We connect Processing to the USB port on which we are uploading the arduino sketch.Once it is done we can send commands to the serial port of the arduino which will then send infrared signals to your appliance through IR LEDs.

In this instructable I will be showing you how to operate a Sony TV..for those who don't have a Sony TV also I will explain how to control your TVs.......so non-Sony TV guys....donot worry this instructable is just as useful to you too!!!

Step 1: Stuff Needed

This project is very cost effective and can be easily done under a 1000 Indian rupees which is about $15-17 that is considering you don't have an arduino.If you do have an arduino this can be done well under 500 rupees or about $8.

So,here is the stuff you will need:-

1). Arduino UNO

2.) IR receiver TSOP1738 (Although any IR receiver will do)

3.) IR LED(only 1 needed but you can use more for a stronger signal)

4.) 200 ohm resistor

5.) Jumper Wires

6.) Breadboard

7.) Processing software(download from processing.org)

8.) Arduino IDE

You will have to download the Serial library for Processing and the IR library for arduino.......

Now that we have the raw material in Place let us begin.

Step 2: Getting the IR Codes From the Remote

First of all before building the actual project we need to know the codes that the remote was sending to the TV.For -that we need to connect the IR receiver to the arduino.

To connect the receiver to the arduino hold the receiver in such a way that the curve of its head is facing you as shown in the pic.Now the left pin is the OUTPUT pin which you have to connect to the Pin number 11 in your arduino. The center pin is the ground pin which you need to connect to the ground of the arduino. The right pin is the VCC pin which you have to connect to the 5v pin on the arduino.

THIS FOLLOWING STEP IS ONLY FOR NON-SONY USERS...SONY USERS SKIP THIS PARA AND CONTINUE WITH THE NEXT PARA

Next,open examples-libraries-IRremote-irtest on your arduino software. This is an existing code for getting the type of the signal that your remote sends. You have SONY,PANASONIC,JVC,RC5,RC6 and NEC type of signals.Upload the sketch to your arduino and open the serial monitor.Now point your remote to the receiver and press any button.The serial monitor will print RC5 or RC6 or NEC or panasonic or jvc. Remember only that much or note it down somewhere.

SONY USERS CONTINUE FROM HERE

Now open examples-libraries-IRremote-IRrecvDemo in your arduino software. Upload the sketch to your arduino and open the serial monitor.Now point your remote to the receiver and press any button(note the button you are pressing). The serial monitor will print a code.Write this code somewhere along with its corresponding button.

Step 3: The Processing Code

Now we will write the Processing code to connect it with arduino.

RUN THE SKETCH ONLY ONCE THE ARDUINO IS CONNECTED TO THE LAPTOP WITH THE SKETCH UPLOADED

First of all check the port which is being used by arduino by running this code-

import processing.serial.*;
Serial myPort;
String portName = Serial.list(); 
 myPort = new Serial(this, portName, 9600);
println(portName,myPort);//this will give you the port number inside an array for example [0] or [1] or [2]

note down the portname.

Now we will write the code for sending the signal to the arduino.

I made a few rectangles each representing either volume up, volume down,switch on/off etc.

import processing.serial.*;
Serial myPort;  
void setup() 
{  
  background(0,255,223);
  
size(600,600);
  fill(250,21,3);
  rect(100,100,50,50);
  fill(11,250,13);
  rect(200,200,50,50);
  fill(200,120,22);
  rect(300,300,50,50);
  fill(0);
  rect(100,400,70,70);
  fill(226,247,2);
  rect(350,100,65,65);
  fill(211,112,11);
  rect(150,100,50,50);
   
  String portName = Serial.list()[x];//in place of x put the portname you got from the previous code    
myPort = new Serial(this, portName, 9600);
}
void draw(){
if(mouseonrect()==true && mousePressed==true && (mouseButton==LEFT)){//volume up
  myPort.write('1');
  
}
if(mouseonrect2()==true && mousePressed==true && (mouseButton==LEFT)){//up
  myPort.write('2');
     
 
}
if(mouseonrect3()==true && mousePressed==true){//input
  myPort.write('3');
     
  
}
if(mouseonrect()==true && mousePressed==true && (mouseButton==RIGHT)){//volume down
  myPort.write('4');
     
 
 
}
if(mouseonrect2()==true && mousePressed==true && (mouseButton==RIGHT) ){//down
  myPort.write('5');
    
}
if(mouseonrect4()==true && mousePressed==true  ){//ok
  myPort.write('6');
    
}
if(mouseonrect5()==true && mousePressed==true  ){//power
  myPort.write('7');
    
}
if(mouseonrect6()==true && mousePressed==true){
  myPort.write('8');
}
if(mousePressed==false){
  myPort.write('0');
     
}
}
boolean mouseonrect(){
 
 return((mouseX>=100) && (mouseX<=150) && (mouseY>=100) && (mouseY<=150)); 
}
boolean mouseonrect2(){
 
 return((mouseX>=200) && (mouseX<=250) && (mouseY>=200) && (mouseY<=250)); 
}
boolean mouseonrect3(){ 
  return((mouseX>=300) && (mouseX<=350) && (mouseY>=300) && (mouseY<=350)); 
}
boolean mouseonrect4(){ 
  return((mouseX>=100) && (mouseX<=170) && (mouseY>=400) && (mouseY<=470)); 
}
boolean mouseonrect5(){
  return((mouseX>=350) && (mouseX<=415) && (mouseY>=100) && (mouseY<=165));
}
boolean mouseonrect6(){
  
return((mouseX>=150) && (mouseX<=200) && (mouseY>=100) && (mouseY<=150)); 
}

Now just keep the window open and move to the arduino part.

Step 4: The Arduino Setup and Code

First of all dismantle the receiver apparatus as we do not need it anymore.

Now connect the IR LED to the arduino. For this connect the positive part of the LED to pin no.3.This is the default pin for transmission in the IR library.

Connect the negative part of the LED to ground through a 200 ohm resistor.

FOR THE SONY USERS UPLOAD THIS FOLLOWING SKETCH TO YOUR ARDUINO-

#include <IRremote.h>
IRsend irsend;
char val;
void setup()
{
  Serial.begin(9600);
}
void loop() {
    if(Serial.available()){
      val=Serial.read();
      }
      if(val=='1'){
      irsend.sendSony(0x490, 12); 
      delay(40);
    }
  else  if(val=='2'){
      irsend.sendSony(0x2F0, 12); 
      delay(40);
    }
      else if(val=='3'){
      irsend.sendSony(0xa50, 12); 
      delay(40);
    }
       else if(val=='4'){
      irsend.sendSony(0xC90, 12); 
      delay(40);
    }
      else if(val=='5'){
      irsend.sendSony(0xaF0, 12); 
      delay(40);
    }
       else if(val=='6'){
      irsend.sendSony(0xa70, 12); 
      delay(40);
    }
      else if(val=='7'){
      irsend.sendSony(0xa90, 12); 
      delay(40);
    }
    else if(val=='8'){
      irsend.sendSony(0x290, 12);
      delay(40);
      }
    else if(val=='0'){
      }
      
}

just replace the codes with the ones you have noted down...Remember to add the 0x though coz that is needed for transmitting the codes

In this code 0x430 is the volume up signal....I think..

FOR PEOPLE WHO HAVE PANASONIC/JVC/NEC/RC5/RC6..JUST REPLACE sendSony with sendPanasonic/sendJVC/sendRC5/sendRC6..the 0x remains common for all...THE LAST 3 CHARACTERS IN THE CODE(FOR EXAMPLE 430 IN 0x430) WILL BE DIFFERENT FOR DIFFERENT FOR DIFFERENT SONY DEVICES AS WELL AS THE OTHER NON-SONY DEVICES

Step 5: RUNNING THE CODE

Now upload the arduino sketch to the arduino board before running the Processing code.

Once you run the Processing code point the IR LED to your TV and click on the rectangles in the Processing window(make sure to keep the arduino connected to the Laptop...It will not work if you connect the arduino to the 9v battery).

Your project is now ready....enjoy!!!

Thank you all for viewing this instructable. I hope it helped you and you enjoyed making it.

Do post your thoughts,comments,doubts etc. in the comments section below.