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
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