BlueTooth + RF module

Hi guys,

I have little problem in my coding, so any help is welcome…
Nano is connected with Mega via RF Module. Bluetooh module is connected on Mega. I want to ON/OFF LED on Nano with my phone. (you can see condition ‘distance’ in my code. That is for my sonars (they are connected to Mega). When distance is between 20 and 30, AND button on my android app is pressed, THEN send data to Nano)

Code on Nano (receiver) is working great, I’ve tested it with some examples.
My problem is Transmitter code (I think problem is with defining BT)
Here is the part of code that contains transmitting data. Where I’m making mistake?

void setup() {
  vw_setup(2000);	 // rf komunikacija Bits per sec
  vw_set_tx_pin(3); //rf komunikacija Transmitter Data Pin to Digital Pin 3
void loop() 
   if(Serial1.available() > 0){
 state =;
if (distance < 30 && distance > 20  && state == '1' && flag == 0) { Serial.println( "OPASNOST - ZONA1"); 
char *msg2 = "1";// RF send 5 to the receiver
vw_send((uint8_t *)msg2, strlen(msg2));// RF send the message to the receiver
   vw_wait_tx(); // RF Wait until the whole message is gone
flag = 1;


Also to mention, when I delete condition

&& state == '1' && flag == 0

Everything works fine, but I haven’t possibility to control that via my phone…

If anyone sees where I mamking mistake, I will apprecitate any help.
Thanks in advance…

If anyone sees where I mamking mistake, I will apprecitate any help.

The problem is that you are posting code where you think that maybe the problem is. Since we can't see all of the code, all that we can do is assume that you are wrong. Either in the assumptions that you have made or in the code that you have written.

If you really want help, you'll post ALL of your code.

Before you do that, though, format it properly. NOTHING follows the { on the same line.


Make sure that the comments do not say stupid things like:

char *msg2 = "1";// RF send 5 to the receiver