Serial monitor stops showing data. Rf receiver (RC-Switch)

Hi,

In my current project, I have a garage door opener sending codes to a 433 MHz RF receiver. While the program is running, if I press any of the 4 buttons on the remote, the serial monitor shows the correct "rfscene", from 0-3.

After a little while however, several seconds/inputs. The serial monitor stops showing data altogether, no matter how often/slow/long/short I press the remote button.

Code below, please advise if you have a suggestion.

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();
int rfscene = 0;
int rfDelay;  //used to delay how often rfscene is output to serial monitor

void setup() {
  Serial.begin(9600);
  mySwitch.enableReceive(0);  // Receiver on interrupt 0 => that is pin #D2
}

void loop() {
  if (mySwitch.available()) {
    unsigned long int rfvalue = mySwitch.getReceivedValue();
    //Serial.print(rfvalue);
    switch(rfvalue){
      case 11302456: mySwitch.disableReceive();
                     rfscene = 0;
                     break;
      case 11302449: mySwitch.disableReceive();
                     rfscene = 1;
                     break;
      case 5408930: mySwitch.disableReceive();
                     rfscene = 2;
                     break;
      case 11302450:mySwitch.disableReceive();
                     rfscene = 3;
                     break;
    }
    Serial.print(rfscene);

    rfDelay=millis();
    while(millis()<rfDelay+500){}

    mySwitch.resetAvailable();
    mySwitch.enableReceive(0); 
  }
    
  }

Where do you find RCSwitch.h?

It's rc-switch.

That works well, it receives the data from the rf remote fine. Just after a certain time or certain amount of data, it stops.

It dies at 66 tries... 33 seconds... search for a timeout?
[edit]
You are overflowing this int

unsigned long rfDelay;
1 Like

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