433 MHz RF transmitter and receiver

Hello guys I just bought new RF modules and I tried to create simple code to understand how it works. Please help me with the code I am so sad :confused:

Here is the Transmitter:

#include <VirtualWire.h>
const int D = 5;
const int B = 3;

int B_Val = 0;
int D_Val = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(B, INPUT);
  pinMode(D, INPUT);

  vw_setup(2000);
  vw_set_tx_pin(9);
}

void loop()
{
    
    
    char c = Serial.read();
    
    
    
    if(digitalRead(D) == LOW)
    {
        vw_send((uint8_t *)0, 1);
        
    }
    
    
    if(digitalRead(B) == LOW)
    {
     
       vw_send((uint8_t *)1, 1);  
    }
   
    /*
    if(c == '1')
    {
      vw_send((uint8_t *)c, 1);
    }
    else if(c == '0')
    {
      vw_send((uint8_t *)c, 1);
    }
    */

}

And here receiver:

#include <VirtualWire.h>

void setup()
{
  pinMode(6,OUTPUT);
  digitalWrite(6, LOW);
  
  vw_setup(2000);
  vw_set_rx_pin(7);
  vw_rx_start();
}

void loop()
{
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  uint8_t buf[buflen];
  
  if(vw_get_message(buf, &buflen))
  {
    for(int i = 0;i < buflen; i++)
    {
      if(buf[i] == '1')
      {
        digitalWrite(6,HIGH);
      }
      else if(buf[i] == '0')
      {
        digitalWrite(6,LOW);
      }
    }
  }
}

I need to understand how it works so please help me... My dream is to create RC Car controlled with bluethooth or RF. I need to understand both. Thanks for help :slight_smile:

MonsterT:
I need to understand how it works so please help me... My dream is to create RC Car controlled with bluethooth or RF. I need to understand both. Thanks for help :slight_smile:

Just use XBees (IMHO)

Something cheaper. I know how to control via Bluethooth but I have also arduino Joystick Shield, therefore I need to learn how to use RF and so. Is NRF24L01 good idea ?

MonsterT:
Something cheaper. I know how to control via Bluethooth but I have also arduino Joystick Shield, therefore I need to learn how to use RF and so. Is NRF24L01 good idea ?

Well, in my experience, the NRF24L01s can be a little fickle at times, difficult to set up with correct library, power issues, etc., but work like a charm once you get everything worked out. Why can't you use bluetooth with the joystick sheild?

Please help me with the code I am so sad :confused:

What is it supposed to do and what does it do?

It should classic RC car. Controlled with 2-axys joystick and 6 buttons. I can with bluethooth but its challenging to try and learn something new like RF.

So I need to use buttons to control RC car over 433Mhz modules.

Bluetooth is RF.

Omg man :smiley: But I meant the 433Mhz communication