IR Reciever - Need help

I recently ordered an IR receiver and got it today. But when I had uploaded this sketch to it the led I was controlling with a remote control would just blink…

Is there something wrong with the sketch or is it the receiver or the led?

Here’s the sketch.

#include <IRremote.h>

int RECV_PIN = 18;
int state = 0;
IRrecv irrecv(RECV_PIN);
int led = 17;
decode_results results;

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

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
  delay(100);
  if (results.value == 0xE0E036C9) { //Button is pressed
    if (state == 0) {
      digitalWrite(led, HIGH);
      state = 1;
    } else {
      digitalWrite(led, LOW);
      state = 0;
    }
  }
}

Hi SMM2,

Do you see the println outputs? Do they come out as fast as the LED blinks?

Also, does the HEX value match the "button pressed" value?

Once you receive 0xE0E036C9 the LED will blink until you receive something else. If you press a different button does the LED stop blinking?

If you want the LED to change state only when you receive another 0xE0E036C9 you would put the second half of loop():

  if (results.value == 0xE0E036C9) { //Button is pressed
    if (state == 0) {
      digitalWrite(led, HIGH);
      state = 1;
    } else {
      digitalWrite(led, LOW);
      state = 0;
    }
  }

INSIDE the 'if' where you detect a new message:

  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
      ////  LIKE HERE
  }