Remote controled LED

Hi
i just would like to remotely control a LED with my TV remote and a IR Receiver. Everything works except my code...

#include <IRremote.h>

int IRpin = 9;
IRrecv irrecv(IRpin);
decode_results results;
int led = 11;
int lum = 128;
void setup()
{
  Serial.begin(9600);
  pinMode(11, OUTPUT);
  pinMode(9, INPUT);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() 
{
  if (irrecv.decode(&results)) 
    {
      Serial.println(results.value, DEC); // Print the Serial 'results.value'
      irrecv.resume();   // Receive the next value
      if (results.value == 2060) {
        Serial.println("allumage");
        analogWrite(led, lum);
      } else if ((results.value == 2080 || results.value == 3520384096 || results.value == 2524690444) && lum < 255) {
        Serial.println("+ : " + String(lum));
        lum++;
        analogWrite(led, lum);
      } else if ((results.value == 2081 || results.value == 2474357589 || results.value == 3470051241) && lum > 0) {
        Serial.println("- : " + String(lum));
        lum--;
        analogWrite(led, lum);
      } else if (results.value == 1268342361) {
        Serial.println("off");
        analogWrite(led, 0);        
      }  
    }
}

I receive the good messages by IR and it goes to the Serial monitor but if lum < 255 the LED stays off and if it is 255 it's on. No fade or whatever. I tried the same with the Fade Arduino Example and it fades... Where's the error ?
Thank you

int IRpin = 9;
IRrecv irrecv(IRpin);
decode_results results;
int led = 11;
int lum = 128;
void setup()
{
  Serial.begin(9600);
  pinMode(11, OUTPUT);
  pinMode(9, INPUT);

Why do you bother giving the pins names?

"I'm not a number; I'm a name!" - Bob Seger

Which Arduino do you have?

What is that code supposed to be doing?
The odds that you will get a result equal to say 3520384096 are a little remote ( no pun intended ) aren't they?
Did you write that?
What library are you using?

Hi,
Sorry I had forgotten these details :stuck_out_tongue:
First, I'm using IRemote with an Arduino Uno. Why having given names ? Simple, at the end I will input the pin numer with my remote but I have forgotten to change it in the pinMode()...
And for the result, it's simple. Before writing this code, I used IRemote to create an Excel file with all the equivalents for my TV Remote (so the + is the Program+, the - is the Program-, the Power is the Power button and the off is a red button but actually I don't know its real utility), so it's not random, it's what I got, and I have three numbers each time because depending of if you keep the button pressed or not it will send a different value.
And if it was not clear enough, everything works except the LED which is either off or on, but can't fade when I keep the P- button pressed - or P+ -...

The analogWrite() function needs a timer. The IR library needs a timer. It is possible that they are trying to use the same timer, and the IR library is winning. Try using pin 3 or 5 for the LED pin.

If you consistently used the NAME you assigned to the pin, you'd only need to change one line of code. As it is, you have to change more than one.

OK... I tried with pin 3 and it did the same, but pin 5 worked (the fade effect is only visible when lum < 50 but I think it must be my eyes :D)... so I can't use other PWM than 5 with IRemote ? That's a little deconcerting...

(and I put the name everywhere in my code just before people noted it :))

the fade effect is only visible when lum < 50 but I think it must be my eyes

Or that fact that you aren't using a current-limiting resistor. Or, are you?

so I can't use other PWM than 5 with IRemote ?

There are 6 PWM pins, using three timers. Using the IR library should still leave you 4 PWM pins. I thought that 3 and 5 shared the same timer, so it's strange that 5 worked, but 3 didn't. 9 and 10 share a timer, as do 11 and 12. Or, at least I think that's the way they are grouped. Try all 6 pins, and see for yourself.

Of course I am using a current limiting resistor !
And I'll see this and post the results it always can be useful.

I thought that 3 and 5 shared the same timer,

No it is pins 3 & 11 that share the same timer, ( timer 2 ) which explains why it would not work.