Playing around with rf 433

Hi all, i was playing around with my uno and mini and rf communication.
The uno is the transmitter and if the mini recieves a signal a green light goes on and a red light on no signal. That works ok but where i don’t succeed is when the transmitter goes offline (disconnect usb from uno) the green light stays on for a few minutes and then goes off while it should be the red one that comes on because the signal is gone and if i look at the serial monitor i can see the feed stopping.

Transmitter code:

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

void setup() {
  mySwitch.enableTransmit(9);  // Using Pin #9
}

void loop() {
  mySwitch.send("10000100011000000000010100");
  delay(1000);  
}

Reciever code:

/*
  Simple example for receiving

  http://code.google.com/p/rc-switch/

  Need help? http://forum.ardumote.com
*/

#include <RCSwitch.h>
int LedRed = 6; //red led
int LedGreen = 7; //green led

RCSwitch mySwitch = RCSwitch();

void setup() {
  Serial.begin(9600);
  mySwitch.enableReceive(0);  // Receiver on inerrupt 0 => that is pin #2
  pinMode(LedGreen, OUTPUT); //sets green led as output
  pinMode(LedRed, OUTPUT); //sets red led as output
}

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

    int value = mySwitch.getReceivedValue();

    if (value == 0) {
      Serial.print("NO SIGNAL !!");
      Serial.println(); 
      digitalWrite(LedGreen, LOW);
      digitalWrite(LedRed, HIGH);
    } 
    else {
      Serial.print("SIGNAL OK !!");
      Serial.println(); 
      digitalWrite(LedGreen, HIGH);
      digitalWrite(LedRed, LOW);
    }
    mySwitch.resetAvailable();
  }
}

Thanks for the tips !

Hi, We will need to see the Rx code as that will be where the problem is, the Tx is turned off.... Sorry I can see that both are in the one code box. Tom.... :)

On the receiver side, you call mySwitch.available(), and do nothing if that function returns 0. So, I would not expect the red or green LEDs to ever get turned off.

The serial output generated when mySwitch.getReceivedValue() returns 0 is wrong. 0 does NOT mean that there was no data. mySwitch.available() == 0 means that there is no data.