Philips TV Remote: Lamp and Servo control

I've got some TV remote code here that might be useful for other projects.

Channel up and down turns the lamp on and off:

Here a TV remote controls a servo and makes an LED blink:

They both use the IR remote library found here: A Multi-Protocol Infrared Remote Library for the Arduino
My code is written for Philips, but the IR library can be used for several different remotes. You'll have to change some of the values in the code for other remotes. There's a forum page about the library here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1251570417

The lamp is plugged into a powerswitchtail. It's a short extension cord with a relay built in that you can turn on and off like you would an LED. Information.com People Search | Free People Finder & White Pages - Locate Anyone

Ingredients for these projects:
1 IR receiver
a 220 ohm resistor for the receiver
the downloaded IR remote library from the link above
powerswitchtail for the lamp or other appliance

The lamp code:

//LAMP CODE
//Channel up turns it on , Channel down turns it off
//Also the mute button can click a second powerswitchtail on or off
#include <IRremote.h>

int RECV_PIN = 11;  //connect IR receiver to pin 11
IRrecv irrecv(RECV_PIN);
decode_results results;

int power = 1;
int buttonState = 0;
int lastpressed = 0;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
pinMode(13, OUTPUT);  //The Powerswitchtail is treated just like an LED
pinMode(8, OUTPUT);  //I threw in some code for the mute button also for another powerswitchtail
}

void loop() {
unsigned long codeValue;

 /*
INPUT codeValue KEY (for Philips Magnavox)  
Every button has 2 possible values.  Each one works.
CHANNEL UP = 32 or 2080
CHANNEL DOWN = 33 or 2081
VOL UP= 16, 2064
VOL DOWN= 17, 2065
1= 1, 2049
2= 2, 2050
3= 3, 2051
4= 4, 2052
5= 5, 2053
6= 6, 2054
7= 7, 2055
8= 8, 2056
9= 9, 2057 
0= 0, 2048
POWER= 12, 2060
MUTE=  13, 2061
MENU= 59, 2107
STATUS= 15, 2063
*/
  
  if (irrecv.decode(&results) ) {
//     Serial.println (results.value, HEX) ;
  
  codeValue = results.value;
  


  //Channel up and down turn it on or off
  if (codeValue == 32 || codeValue == 2080){  //channel up
  digitalWrite(13, HIGH);
  
  Serial.println("Channel On");
  }
  
   if (codeValue == 33 || codeValue == 2081){
  digitalWrite(13, LOW);
  Serial.println("Channel Off");
   }


// The mute button can control another powerswitchtail
 if (codeValue == 13 || codeValue == 2061){  //mute
 
if (lastpressed != codeValue){ 
  
  if (power == 1){
  digitalWrite(8, HIGH);
 
Serial.println("ON");
lastpressed = codeValue;
 power = 5;
 }
}


if (lastpressed != codeValue){
  
  if (power == 5){
  digitalWrite(8, LOW);
 
Serial.println("OFF");
lastpressed = codeValue;
power = 1;
}
}

 }
  
    irrecv.resume(); // Receive the next value
  }

delay(10);
}

The servo and LED code:

#include <IRremote.h>

#include <ServoTimer1.h>

ServoTimer1 servo1;

int RECV_PIN = 11;  // connect IR receiver to pin 11
IRrecv irrecv(RECV_PIN);
decode_results results;




void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver

pinMode(13, OUTPUT);  //LED on pin 13

 servo1.attach(9);   // servo on pin 9
}

void loop() {
unsigned long codeValue;

/*
Phillips MAGNAVOX VALUES
CHANNEL UP = 32, 2080
CHANNEL DOWN = 33, 2081
VOL UP= 16, 2064
VOL DOWN= 17, 2065
1= 1, 2049
2= 2, 2050
3= 3, 2051
4= 4, 2052
5= 5, 2053
6= 6, 2054
7= 7, 2055
8= 8, 2056
9= 9, 2057 
0= 0, 2048
POWER= 12, 2060
MENU= 59, 2107
STATUS= 15, 2063
*/
  
  if (irrecv.decode(&results) ) {
//     Serial.println (results.value, HEX) ;
  
  codeValue = results.value;
  Serial.println(codeValue);

  
  if (codeValue == 59 || codeValue == 2107){ // menu
  digitalWrite(13, HIGH);
  delay(100);
  digitalWrite(13, LOW);  
  }
  
    if (codeValue == 32 || codeValue == 2080){  // channel up
  servo1.write(175);
    }
  
   if (codeValue == 16 || codeValue == 2064){  // vol up
  servo1.write(90);
    }
    
     if (codeValue == 33 || codeValue == 2081){  // channel down
  servo1.write(5);
    }
  
    irrecv.resume(); // Receive the next value
  }




delay(10);
}

Very nice! :slight_smile: