Problem help code ...

hello friend how are have this problem I need help I am creating a code which works but I have a little problem that I have divided my work into 3 parts
1-) by infrared control my air conditioner
2) remote control for the lights in my house (control infrared tv)
3) controlled via web interface (php and serial port) the lights and the air conditioner from anywhere by internet.

works fine the first time, but when I send the signal to the IR LED connected to the Arduino pin 3 to turn on my air control with the party in control of my tv stops working. I have to manually reset the arduino mind to run all over again

/*
-Codigo Control Home..
-Email: greber.roamir@gmail.com
-Pin 3 controla el led IR
-Pine Receptor vout 12
Gnd Gnd
Vcc +5v
*/

#include <IRremote.h>
int RECV_PIN = 12;
int PIN_11 = 11;
int PIN_10 = 10;
int PIN_9 = 9;
int PIN_8 = 8;
int PIN_7 = 7;
int PIN_6 = 6;
int PIN_5 = 5;
int PIN_4 = 4;
int PIN_3 = 3;
int PIN_2 = 2;

int BAUD_RATE = 9600;

IRsend irsend; // Se conecta el pin # 3 Led IR
IRrecv irrecv(RECV_PIN);
decode_results results;

///////////////////////////////////////////////////////////////////// Codigo de Control de Aire Acondicionado por Infrarojo
unsigned int powerOn[22] = {
850,800,1700,800,850,1650,850,800,900,750,900,800,1700,1600,1750,1600,1700,1650,850,};
unsigned int powerOff[22] = {
850,800,1700,800,850,1650,850,800,900,750,900,800,1700,1600,1750,1600,1700,1600,900,};
unsigned int temp1[22] = {
900,800,850,800,1700,1650,900,750,850,800,900,800,850,800,1700,800,850,1650,1700,1600,900,};
unsigned int temp2[22] = {
900,750,1750,750,900,1600,900,800,850,800,900,750,900,800,1700,800,850,1650,850,800,1700,};

void setup()
{
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
pinMode(2, OUTPUT);
Serial.begin(BAUD_RATE);
{
irrecv.enableIRIn(); // Inicio del Receptor

}
}
int on = 1;

void loop(){
cmd();
ctl();
}

/////////////////////////////////////////////////////////////////////

void cmd()
{
if (Serial.available() > 0) {
int command = Serial.read();
if (command == 'w') {
irsend.sendRaw(powerOn,22,38); // Para enviar señal IR al Presionar en consola serial "w" Power ON
Serial.println("LED ON");
}
else if (command == 'x') {
irsend.sendRaw(powerOff,22,38); // Para enviar señal IR al Presionar en consola serial "x" Power OFF
Serial.println("LED OFF");
}
else if (command == 'y') {
irsend.sendRaw(temp1,22,38); // Para enviar señal IR al Presionar en consola serial "y" Temp Up
Serial.println("LED ON");
}
else if (command == 'z') {
irsend.sendRaw(temp2,22,38); // Para enviar señal IR al Presionar en consola serial "z" Temp Down
Serial.println("LED OFF");

/////////////////////////////////////////////////////////////////////

}
else if (command == 'a') {
digitalWrite(2, HIGH);
Serial.println("LED ON");
}
if (command == 'b') {
digitalWrite(2, LOW);
Serial.println("LED OFF");
}
else if (command == 'c') {
digitalWrite(4, HIGH);
Serial.println("LED ON");
}
if (command == 'd') {
digitalWrite(4, LOW);
Serial.println("LED OFF");
}
else if (command == 'e') {
digitalWrite(5, HIGH);
Serial.println("LED ON");
}
if (command == 'f') {
digitalWrite(5, LOW);
Serial.println("LED OFF");
}
else if (command == 'g') {
digitalWrite(6, HIGH);
Serial.println("LED ON");
}
if (command == 'h') {
digitalWrite(6, LOW);
Serial.println("LED OFF");
}
else if (command == 'i') {
digitalWrite(7, HIGH);
Serial.println("LED ON");
}
if (command == 'j') {
digitalWrite(7, LOW);
Serial.println("LED OFF");
}
else if (command == 'k') {
digitalWrite(8, HIGH);
Serial.println("LED ON");
}
if (command == 'l') {
digitalWrite(8, LOW);
Serial.println("LED OFF");
}
else if (command == 'm') {
digitalWrite(9, HIGH);
Serial.println("LED ON");
}
if (command == 'n') {
digitalWrite(9, LOW);
Serial.println("LED OFF");
}
else if (command == '0') {
digitalWrite(10, HIGH);
Serial.println("LED ON");
}
if (command == 'p') {
digitalWrite(10, LOW);
Serial.println("LED OFF");
}
else if (command == 'q') {
digitalWrite(11, HIGH);
Serial.println("LED ON");
}
if (command == 'r') {
digitalWrite(11, LOW);
Serial.println("LED OFF");
}
}
}
void ctl() {
if(irrecv.decode(&results)) {
if (results.value == 33431775) { // Codigo IR Control Infrarojo Tecla # 1
{
on = !on;
digitalWrite(2, on ? HIGH : LOW);
}
}
{
if (results.value == 33464415) { // Codigo IR Control Infrarojo Tecla # 2
{
on = !on;
digitalWrite(4, on ? HIGH : LOW);
}
}
{
if (results.value == 33448095) { // Codigo IR Control Infrarojo Tecla # 3
{
on = !on;
digitalWrite(5, on ? HIGH : LOW);
}
}
{
if (results.value == 33480735) { // Codigo IR Control Infrarojo Tecla # 4
{
on = !on;
digitalWrite(6, on ? HIGH : LOW);
}
}
{
if (results.value == 33427695) { // Codigo IR Control Infrarojo Tecla # 5
{
on = !on;
digitalWrite(7, on ? HIGH : LOW);
}
}
{
if (results.value == 33460335) { // Codigo IR Control Infrarojo Tecla # 6
{
on = !on;
digitalWrite(8, on ? HIGH : LOW);
}
}
{
if (results.value == 33444015) { // Codigo IR Control Infrarojo Tecla # 6
{
on = !on;
digitalWrite(9, on ? HIGH : LOW);

}
}
irrecv.resume(); // Recibe Proximo valor

}
}
}
}
}
}
}
}

I am not sure if this will help , but the IRremote library uses pin 11 for the receive pin , and you indicate pin 12 in your sketch.
int RECV_PIN = 11;// copied from the IRremote library

Also, you are defining pin 3 in your code , which is the IRled in the IRremote library .

Have you set up and tested the posted code from Ken Shirriff 1st ? This will ensure that you can receive and send code to you AC and TV with good results .

Hope this can help,
Bob D

thanks bob I made the corrections you suggested but still the problem continues

the code work the first time I turn on the LED with the remote control of my tv
by serial console turn on and turn off the LED while the turn off or turn on control of tv, the problem is when for serial console switch on my ipod, which works turn on and turn off preview songs, and when I use my control tV, and / or serial console to turn on or off the lED does not work, reset the arduino and everything funiona again ...

/*
-Codigo Control Home..
-Email: greber.roamir@gmail.com
-Pin 3 controla el led IR
-Pine Receptor vout 11
Gnd Gnd
Vcc +5v
*/

#include <IRremote.h>
int RECV_PIN = 11;
int PIN_12 = 12;
int PIN_10 = 10;
int PIN_9 = 9;
int PIN_8 = 8;
int PIN_7 = 7;
int PIN_6 = 6;
int PIN_5 = 5;
int PIN_4 = 4;
int PIN_2 = 2;

int BAUD_RATE = 9600;

IRsend irsend; // Se conecta el pin # 3 Led IR
IRrecv irrecv(RECV_PIN);
decode_results results;

///////////////////////////////////////////////////////////////////// Codigo de Control de Aire Acondicionado por Infrarojo
unsigned int powerOn[22] = {
850,800,1700,800,850,1650,850,800,900,750,900,800,1700,1600,1750,1600,1700,1650,850,};
unsigned int powerOff[22] = {
850,800,1700,800,850,1650,850,800,900,750,900,800,1700,1600,1750,1600,1700,1600,900,};
unsigned int temp1[22] = {
900,800,850,800,1700,1650,900,750,850,800,900,800,850,800,1700,800,850,1650,1700,1600,900,};
unsigned int temp2[22] = {
900,750,1750,750,900,1600,900,800,850,800,900,750,900,800,1700,800,850,1650,850,800,1700,};

void setup()
{
pinMode(12, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
pinMode(2, OUTPUT);
Serial.begin(BAUD_RATE);
{
irrecv.enableIRIn(); // Inicio del Receptor
irrecv.blink13(true);
}
}
int on = 1;

void loop(){
cmd();
ctl();
}

/////////////////////////////////////////////////////////////////////

void cmd()
{
if (Serial.available() > 0) {
char command = Serial.read();
if (command == 'w') {
irsend.sendRaw(powerOn,22,38); // Para enviar señal IR al Presionar en consola serial "w" Power ON
Serial.println("LED ON");
}
else if (command == 'x') {
irsend.sendRaw(powerOff,22,38); // Para enviar señal IR al Presionar en consola serial "x" Power OFF
Serial.println("LED OFF");
}
else if (command == 'y') {
irsend.sendRaw(temp1,22,38); // Para enviar señal IR al Presionar en consola serial "y" Temp Up
Serial.println("LED ON");
}
else if (command == 'z') {
irsend.sendRaw(temp2,22,38); // Para enviar señal IR al Presionar en consola serial "z" Temp Down
Serial.println("LED OFF");

/////////////////////////////////////////////////////////////////////

}
else if (command == 'a') {
digitalWrite(2, HIGH);
Serial.println("LED ON");
}
if (command == 'b') {
digitalWrite(2, LOW);
Serial.println("LED OFF");
}
else if (command == 'c') {
digitalWrite(4, HIGH);
Serial.println("LED ON");
}
if (command == 'd') {
digitalWrite(4, LOW);
Serial.println("LED OFF");
}
else if (command == 'e') {
digitalWrite(5, HIGH);
Serial.println("LED ON");
}
if (command == 'f') {
digitalWrite(5, LOW);
Serial.println("LED OFF");
}
else if (command == 'g') {
digitalWrite(6, HIGH);
Serial.println("LED ON");
}
if (command == 'h') {
digitalWrite(6, LOW);
Serial.println("LED OFF");
}
else if (command == 'i') {
digitalWrite(7, HIGH);
Serial.println("LED ON");
}
if (command == 'j') {
digitalWrite(7, LOW);
Serial.println("LED OFF");
}
else if (command == 'k') {
digitalWrite(8, HIGH);
Serial.println("LED ON");
}
if (command == 'l') {
digitalWrite(8, LOW);
Serial.println("LED OFF");
}
else if (command == 'm') {
digitalWrite(9, HIGH);
Serial.println("LED ON");
}
if (command == 'n') {
digitalWrite(9, LOW);
Serial.println("LED OFF");
}
else if (command == '0') {
digitalWrite(10, HIGH);
Serial.println("LED ON");
}
if (command == 'p') {
digitalWrite(10, LOW);
Serial.println("LED OFF");
}
else if (command == 'q') {
digitalWrite(12, HIGH);
Serial.println("LED ON");
}
if (command == 'r') {
digitalWrite(12, LOW);
Serial.println("LED OFF");
}
}
}
void ctl() {
if(irrecv.decode(&results)) {
if (results.value == 3495472343) { // Codigo IR Control Infrarojo Tecla # 1
{
on = !on;
digitalWrite(2, on ? HIGH : LOW);
}
}
{
if (results.value == 2164211903) { // Codigo IR Control Infrarojo Tecla # 2
{
on = !on;
digitalWrite(4, on ? HIGH : LOW);
}
}
{
if (results.value == 2164244543) { // Codigo IR Control Infrarojo Tecla # 3
{
on = !on;
digitalWrite(5, on ? HIGH : LOW);
}
}
{
if (results.value == 2164203743) { // Codigo IR Control Infrarojo Tecla # 4
{
on = !on;
digitalWrite(6, on ? HIGH : LOW);
}
}
{
if (results.value == 2164236383) { // Codigo IR Control Infrarojo Tecla # 5
{
on = !on;
digitalWrite(7, on ? HIGH : LOW);
}
}
{
if (results.value == 2164220063) { // Codigo IR Control Infrarojo Tecla # 6
{
on = !on;
digitalWrite(8, on ? HIGH : LOW);
}
}
{
if (results.value == 33444015) { // Codigo IR Control Infrarojo Tecla # 7
{
on = !on;
digitalWrite(9, on ? HIGH : LOW);

}
}
irrecv.resume(); // Recibe Proximo valor

}
}
}
}
}
}
}
}

several remarks

please use code tags when posting code, makes it more readable (# button above smileys)

read and learn about the use of array's - it could reduce your code substantially
-http://arduino.cc/en/pmwiki.php?n=Tutorial/Array -

read and learn about switch(command) - it is a nicer if then else if ... format

Keep comments short and to the point

    if (command == 'w') {
      irsend.sendRaw(powerOn,22,38); // Para enviar señal IR al Presionar en consola serial "w"  Power ON
...

the comment is obvious from the code, so it can be omitted without loosing clarity

    if (command == 'w') {
      irsend.sendRaw(powerOn,22,38);
...

saves you typing

A small rewrite of the ctl() function, removed unneeded brackets, minimized comments

void ctl()
{
  if (irrecv.decode(&results))
  {
    // # 1
    if (results.value == 3495472343) 
    {
      on = !on;
      digitalWrite(2, on) ;  // TRUE == HIGH  FALSE == LOW
    }
    // # 2
    if (results.value == 2164211903)
    {
      on = !on;
      digitalWrite(4, on);
    }

    // # 3
    if (results.value == 2164244543) 
    {
      on = !on;
      digitalWrite(5, on );
    }

    // # 4
    if (results.value == 2164203743)
    {
      on = !on;
      digitalWrite(6, on);
    }

    // # 5
    if (results.value == 2164236383)
    {
      on = !on;
      digitalWrite(7, on);
    }

    // # 6
    if (results.value == 2164220063) 
    {
      on = !on;
      digitalWrite(8, on);
    }

    // # 7
    if (results.value == 33444015) 
    {
      on = !on;
      digitalWrite(9, on);
    }
    irrecv.resume(); // Recibe Proximo valor
  }
}

Q: why using one variable on to hold the state of all pins ?

thanks robtillaart did what you suggested thank you very much, but I still have the same problem

the part that controls the LED infrared IR when executed by the serial port functions and control my device but the party goes down on and off with the remote control of my tv, reset the arduino and everything works again
the problem gives it when I check the device that controls the IR ..

/*
-Codigo Control Home..
-Email: greber.roamir@gmail.com
-Pin 3 controla el led IR
-Pine Receptor vout 11
Gnd Gnd
Vcc +5v
*/

#include <IRremote.h>
int RECV_PIN = 11;
int PIN_12 = 12;
int PIN_10 = 10;
int PIN_9 = 9;
int PIN_8 = 8;
int PIN_7 = 7;
int PIN_6 = 6;
int PIN_5 = 5;
int PIN_4 = 4;
int PIN_2 = 2;
int timer = 50;
int BAUD_RATE = 9600;

IRsend irsend; // Se conecta el pin # 3 Led IR
IRrecv irrecv(RECV_PIN);
decode_results results;

///////////////////////////////////////////////////////////////////// Codigo de Control de Aire Acondicionado por Infrarojo
unsigned int powerOn[22] = {
850,800,1700,800,850,1650,850,800,900,750,900,800,1700,1600,1750,1600,1700,1650,850,};
unsigned int powerOff[22] = {
850,800,1700,800,850,1650,850,800,900,750,900,800,1700,1600,1750,1600,1700,1600,900,};
unsigned int temp1[22] = {
900,800,850,800,1700,1650,900,750,850,800,900,800,850,800,1700,800,850,1650,1700,1600,900,};
unsigned int temp2[22] = {
900,750,1750,750,900,1600,900,800,850,800,900,750,900,800,1700,800,850,1650,850,800,1700,};

void setup()
{
pinMode(12, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
pinMode(2, OUTPUT);
Serial.begin(BAUD_RATE);
{
irrecv.enableIRIn(); // Inicio del Receptor
irrecv.blink13(true);
}
}
int on = 1;

void loop(){
cmd();
ctl();
}

/////////////////////////////////////////////////////////////////////

void cmd()
{
if (Serial.available() > 0) {
char command = Serial.read();
if (command == 'w') {
irsend.sendRaw(powerOn,22,38);

}
if (command == 'x') {
irsend.sendRaw(powerOff,22,38);

}
if (command == 'y') {
irsend.sendRaw(temp1,22,38);

}
if (command == 'z') {
irsend.sendRaw(temp2,22,38);

/////////////////////////////////////////////////////////////////////

}
if (command == 'a') {
digitalWrite(2, HIGH);
Serial.println("LED ON");
}
if (command == 'b') {
digitalWrite(2, LOW);
Serial.println("LED OFF");
}
if (command == 'c') {
digitalWrite(4, HIGH);
Serial.println("LED ON");
}
if (command == 'd') {
digitalWrite(4, LOW);
Serial.println("LED OFF");
}
if (command == 'e') {
digitalWrite(5, HIGH);
Serial.println("LED ON");
}
if (command == 'f') {
digitalWrite(5, LOW);
Serial.println("LED OFF");
}
if (command == 'g') {
digitalWrite(6, HIGH);
Serial.println("LED ON");
}
if (command == 'h') {
digitalWrite(6, LOW);
Serial.println("LED OFF");
}
if (command == 'i') {
digitalWrite(7, HIGH);
Serial.println("LED ON");
}
if (command == 'j') {
digitalWrite(7, LOW);
Serial.println("LED OFF");
}
if (command == 'k') {
digitalWrite(8, HIGH);
Serial.println("LED ON");
}
if (command == 'l') {
digitalWrite(8, LOW);
Serial.println("LED OFF");
}
if (command == 'm') {
digitalWrite(9, HIGH);
Serial.println("LED ON");
}
if (command == 'n') {
digitalWrite(9, LOW);
Serial.println("LED OFF");
}
if (command == '0') {
digitalWrite(10, HIGH);
Serial.println("LED ON");
}
if (command == 'p') {
digitalWrite(10, LOW);
Serial.println("LED OFF");
}
if (command == 'q') {
digitalWrite(12, HIGH);
Serial.println("LED ON");
}
if (command == 'r') {
digitalWrite(12, LOW);
Serial.println("LED OFF");
}
}
}
void ctl()
{
if (irrecv.decode(&results))
{
// # 1
if (results.value == 3495472343)
{
on = !on;
digitalWrite(2, on) ; // TRUE == HIGH FALSE == LOW
}
// # 2
if (results.value == 2164211903)
{
on = !on;
digitalWrite(4, on);
}

// # 3
if (results.value == 2164244543)
{
on = !on;
digitalWrite(5, on );
}

// # 4
if (results.value == 2164203743)
{
on = !on;
digitalWrite(6, on);
}

// # 5
if (results.value == 2164236383)
{
on = !on;
digitalWrite(7, on);
}

// # 6
if (results.value == 2164220063)
{
on = !on;
digitalWrite(8, on);
}

// # 7
if (results.value == 33444015)
{
on = !on;
digitalWrite(9, on);
}
irrecv.resume(); // Recibe Proximo valor
}
}

I havent bothered looking at your posted code because it is not formatted within code tags, but your problem sounds like :

After sending IR you need to enable IR receiving again using

enableIRIn();

Hope that helps....