0

I would like to use the IR remote with Arduino to turn on a LED and turn off the same LED when I push on the remote.

That is to say :

  • If I push on 1 I would like the LED turn on
  • If I push on 2 I would like the LED turn off

Here is my code :

#include <IRremote.h>

const int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;

const int L1 = 13;

void setup(){
  Serial.begin(9600);
  irrecv.enableIRIn();
  irrecv.blink13(true);
  pinMode(L1, OUTPUT);
}

void loop(){
  if (irrecv.decode(&results)){
        unsigned int value = results.value;
        Serial.println(value);
        irrecv.resume();
        if(value == 12495){
        digitalWrite(L1, HIGH);
        delay(1000);
        } 
        else if(value == 6375){
        digitalWrite(L1, LOW);
        delay(1000);  
      }

  }
}

But the problem is when I push on 1 I just see the LED turn on but very quickly the LED turns off then whereas I don't push on the button 2.

Could you help me please?

  • Unrelated; there is no need to add the delay(1000); after turning the led on/off. – Gerben Aug 31 '18 at 13:44
1

This line of your sketch irrecv.blink13(true); tells the IRrecv object to flash the LED on and off when an IR signal is received. boarddefs.h in the IRremote folder has pin number 13 defined as the default BLINKLED. The code you have written in loop() is trying to do something different with the same LED. I would remove this line irrecv.blink13(true); then try your sketch again. Once the LED is working correctly, try removing both of these lines delay(1000);.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.