How to wait for a particular IR Signal in Arduino? following code didn't work for me.. your support pls

void loop() {
// put your main code here, to run repeatedly:
if( irrecv.decode(&results)){

while ( value==3772793023){
  value=results.value;
  Serial.println(value);
  irrecv.resume();

}

Help us help you.

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.

Please post a schematic.

Please post an image of your project.

Please describe the problem better then you just did.

code snippets suck.

Are you using a Uno or Mega with the number 3772793023? The Uno, Mega, and a few others cast that number as a 16 bit integer

flow chart attached herewith.

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project.

In the while-loop you never check if there is anything decoded.

unsigned long value = 0;

void loop() {
  do {
    if (irrecv.decode(&results)) {
      value = results.value;
      Serial.println(value);
      irrecv.resume();
    }
  } while (value != 3772793023);

  // Done waiting

}

<#include <IRremote.h>

IRrecv irrecv(9);

unsigned long val=0;
decode_results results;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);// initialize serial monitor
irrecv.enableIRIn();
}

void loop() {
// put your main code here, to run repeatedly:

while (val = 3772793023){
if (irrecv.decode(&results)){
val=(results.value,DEC);
Serial.println(results.value,DEC);
irrecv.resume();
}
}
Serial.print("OK");
}

i used this code ,but it doesn't print "OK" even the 'val' match with the code

= assignment
== comparison

Even if you fix it to "while (val == 3772793023) {" it will not work because 'val' is set to 0 and will never be equal to 3772793023 because you never enter the 'while' body. You want:

while (val != 3772793023) {

That will repeat the decode until the desired input is found.

< while (val == 3772793023){
if (irrecv.decode(&results)){
val=(results.value,DEC);
Serial.println(val);
irrecv.resume();
}
}
Serial.print("OK");
}>
when its apply above code its print "OK" contineously

Yes. See post #8. You never look for input because "(val == 3772793023)" is always false.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.