Rf 433 transmitter and receiver connection.

Hello,

I use 2 Arduino boards. One for transmitter, another one for the receiver with LED.

I want the Receiver’ LED will be on once it gets any message from the transmitter
and the Receiver’s LED will turn off once its disconnected.
The Receiver and the transmitter are connected again, LED will turn on.

I made it work without ‘delay’ problem.

The problem I guess is a ‘delay’ . Without ‘delay’ this code does not work.
But with ‘delay’ it automatically stop running for the few seconds.( ‘delay’ set up time).
Which means every few seconds LED will be on even if receiver is not getting any message from transmitter.

Is there anyone who can help me out?

-------------------------------------------Transmitter code----------------------------------------

#include <VirtualWire.h>
char *controller;
void setup()
{
Serial.begin(9600); // Debugging only
pinMode(13,OUTPUT);
vw_set_tx_pin(12);
vw_setup(4000); // Bits per sec
}
void loop(){
controller=“1” ;
vw_send((uint8_t *)controller, strlen(controller));
digitalWrite(13,1);
}


-------------------------------------------Receiver code----------------------------------------
#include <VirtualWire.h>
void setup()
{
Serial.begin(9600);
pinMode(13,OUTPUT);
vw_set_rx_pin(12);
vw_setup(4000);
vw_rx_start();
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen))
digitalWrite(13,1 );

else digitalWrite(13,0);
delay (4000);

}


Your transmitter is jamming data as fast as it can. Your receiver is sitting on it's ass doing nothing most of the time.

It isn't really clear what you are trying to do, but it seems like a completely different approach is needed.

You should turn the LED on when a packet arrives, and turn it off if nothing arrives WITHIN SOME DEFINED INTERVAL. This means that you need to note when a packet arrives, and turn the LED on.

Periodically, you need to see if the desired interval has elapsed, without receiving any data. If so, turn off the LED.

Turning the LED off the instant that communications, involving sending packets over radios, stops is just not feasible. Turning the LED off if nothing has been received for 10 milliseconds MIGHT be. The baud rate that the radios are operating at (pretty low) will affect how long it takes to receive a packet, and how short the "I didn't get a heartbeat interval" can be.

Do not use delay. It is a half assed approach that you will not have any use for in any more serious project. Delay blocks your code and it ends up doing nothing. Use timer loops instead.

What I do is I always have timer1 in free running mode with prescaler set to 8 and overflow interrupt enabled. And I use this for all my timing tasks throughout the app. In overflow interrupt I increment a 32 bit int to get a 48 bit resolution counter with microsecond precision. This gives correct delays that stay the same regardless of interrupts that run in background and which you can choose whether you code should sit and do nothing or do something else while delay has not expired.

Todo a delay I define a delay like this:
timeout_t tout = timeout_from_now(1000000); // 1 second timeout

Then in some other place I can do:
if(timeout_expired(tout))
// do something

For implementation:
https://github.com/mkschreder/martink/blob/master/arch/m328p/time.c
https://github.com/mkschreder/martink/blob/master/arch/m328p/time.h

Simple and clean and does not suffer the disadvantages of delay(). Delay() is downright evil because all libraries written using it are completely useless in a serious project where timing is important.

PaulS:
Your transmitter is jamming data as fast as it can. Your receiver is sitting on it's ass doing nothing most of the time.

It isn't really clear what you are trying to do, but it seems like a completely different approach is needed.

You should turn the LED on when a packet arrives, and turn it off if nothing arrives WITHIN SOME DEFINED INTERVAL. This means that you need to note when a packet arrives, and turn the LED on.

Periodically, you need to see if the desired interval has elapsed, without receiving any data. If so, turn off the LED.

Turning the LED off the instant that communications, involving sending packets over radios, stops is just not feasible. Turning the LED off if nothing has been received for 10 milliseconds MIGHT be. The baud rate that the radios are operating at (pretty low) will affect how long it takes to receive a packet, and how short the "I didn't get a heartbeat interval" can be.

Thank you for the comment.
It's been only few weeks since I learned about Arduino. The code I used is getting from all website and fixed a little bit. I am sure the code looks really strange.

What I want is exactly what you said.

Turn LED on if receiver getting any data from the transmitter. (LED is on a same board where the receiver is)
Turn LED off if nothing has been received.

I really want to make it using Rf433.
Could you please help me to make this code?

Thank you.