Help with ir remote loop

I have a code here I gets two leds to blink with an ir remote. So when I click the button on my remote, the led`s is just blinking once, it will not loop, why?? please help!!

My code:

#include <IRremote.h>

const int recvPin = 8;
const int led1 = 2;
const int led2 = 3;

IRrecv irReciver(recvPin);
decode_results results;

void setup()
{
  pinMode(led1,OUTPUT);
  pinMode(led2,OUTPUT);
  irReciver.enableIRIn();
  Serial.begin(9600);
}

void loop()
{
  unsigned long recv_value;

  if (irReciver.decode(&results))
  {
    recv_value = results.value;

    if (recv_value == 0xFFA15E)
    {
      digitalWrite(led1,HIGH);
      digitalWrite(led2,HIGH);
      delay(500);
      digitalWrite(led1,LOW);
      digitalWrite(led2,LOW);
      delay(500);
    }
    irReciver.resume();
  }
}

Thanks!!
ps: sorry for my bad English :slight_smile:

it will not loop, why??

Because you haven't written the code to make it "loop".

Assigning a value to recv_value, and doing something based on the value in recv_value, should be completely independent operations.

I am also having a similar problem but not found the solution yet :frowning: . Please reply to my question "How to hold an output state ?" if you find the solution to your problem........

Do you mean it doesnt keep blinking when you keep the button on the remote pressed.

If the IR protocol is NEC (you can check this with IRremote) - you get the repeat code FFFFFFFF after the first code of 0xFFA15E, which would explain why you would get only one blink for every key press.

as a simple test do the following and put ... Serial.println(recv_value); ... before the 2nd if statement.

Hope this helps.

I mean to use one button to turn the blink on and another button to turn it off :slight_smile:

Try this ... it should turn both leds on when you press button with 0xFFA15E value and turn both off when you press a second button.

First you must change the 0x?????? in the code below to the value of your 2nd key

  if (irReciver.decode(&results))
  {
    recv_value = results.value;

    if (recv_value == 0xFFA15E)
    {
      digitalWrite(led1,HIGH);
      digitalWrite(led2,HIGH);

    }
    if (recv_value == 0x??????) //change this 0x?????? to the value of your other button  <<<<<<<<<!!!!!!*********
    {
      digitalWrite(led1,LOW);
      digitalWrite(led2,LOW);
     }
    irReciver.resume();
  }

If this doesn't work fo you, upload a copy of your circuit with the LEDs

Yeh it work with just light, but still no blinking :slight_smile:

Great!

It sounds like you just need some more experience playing with Arduino. You should go thru and try to understand more of the Arduino examples (File->Exmples->...) and I believe, after that, you will be able to program any 'blink' sequence.

If you have already done this, then I suggest you search Google for more examples or download some of the getting started with Arduino books to study.

Best of luck with your project :slight_smile:

I had the same problem, but I found the solution:

Add a new variable that equals 0. the IR remote will change the variable to (1) if it's (0). Otherwise, it will change the variable to (0) if it's 1.

After that, make an (if) statement at the end of the (void loop) function that if the variable equals (0), the two LEDs will blink. Else, they will stay off.

Try it, it's very efficient!