[Solved] Make Arduino do something when it's receiving nothing from RF Receiver

Hi !
I've started three days ago to work on a project with RF transmitter and receiver. The Arduino with the transmitter send a number without a problem and the Arduino with the receiver receive the number without any problem him to.

But, I can't figure out how to get the arduino with the receiver to do something when he gets nothing :frowning:

I'm using the RCswitch library and when the "mySwitch.getReceivedValue()" receive nothing, well, there is nothing in it. Not even a 0, so I don't know what to do.

Hope someone understands what I'm saying. If anyone can help me, I'd be very grateful. Thank you :smiley:

Example for doing something else, when nothing is received:

/*
  Simple example for receiving  
  https://github.com/sui77/rc-switch/
*/

#include "rc-switch\RCSwitch.cpp"

RCSwitch mySwitch = RCSwitch();

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

void loop() {

  if (mySwitch.available()) {
    Serial.print("Received ");
    Serial.println( mySwitch.getReceivedValue());
    mySwitch.resetAvailable();
  }

  else {
    do_something_else(); 
  }
}

You don't really need the "else {}" bit.

I’m such an idiot!
Thank you so much!!

Here is my code for now if you want to see it :

/*
  Simple example for receiving

  https://github.com/sui77/rc-switch/
*/

#include <RCSwitch.h>

uint8_t buf[8] = {
  0
}; /* Keyboard report buffer */
RCSwitch mySwitch = RCSwitch();

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

void loop() {
  if (mySwitch.available()) {


    if (mySwitch.getReceivedValue() == 69) {
      delay(50);

      buf[0] = 0;
      buf[2] = 0x2C;
      Serial.write(buf, 8);
      releaseKey();

      delay(50);

      buf[0] = 0;
      buf[2] = 0x2A;
      Serial.write(buf, 8);
      releaseKey();

      delay(300);

      buf[0] = 0;
      buf[2] = 0x39;
      Serial.write(buf, 8);
      releaseKey();

      delay(50);

      buf[0] = 0;
      buf[2] = 0x1E;
      Serial.write(buf, 8);
      releaseKey();

      delay(50);

      buf[0] = 0;
      buf[2] = 0x1F;
      Serial.write(buf, 8);
      releaseKey();

      delay(50);

      buf[0] = 0;
      buf[2] = 0x27;
      Serial.write(buf, 8);
      releaseKey();

      delay(50);

      buf[0] = 0;
      buf[2] = 0x1E;
      Serial.write(buf, 8);
      releaseKey();

      delay(50);

      buf[0] = 0;
      buf[2] = 0x39;
      Serial.write(buf, 8);
      releaseKey();

      delay(50);

      buf[0] = 0;
      buf[2] = 0x28;
      Serial.write(buf, 8);
      releaseKey();

      delay(50);
      mySwitch.resetAvailable();
      delay(3000);

    }

  }

  else {
    Serial.println("test");

  }


}


void releaseKey()
{
  buf[0] = 0;
  buf[2] = 0;
  Serial.write(buf, 8); // Release key
}

Thanks again!!