How to transmit a defined character from Arduino 1 to Arduino 2

Hello.

My project includes two Arduino UNOs, which are planned to be connected in only one way (one transmitter and one receiver (a pair of 433MHz RF modules are used for this)) to build a controller which is for controlling an car (it’s a chassis kit).

Firsty how I (or better said my group) thought how it should work:
On the one side (the side with the transmitter), when somebody is pushing one or multible of four buttons the controller will send a character (as exampel ‘a’ or ‘b’) as signal to the receiver so that the sketch on that side can read the incoming character (it’s a Serial.Read) and assign this character to a command. Then the arduino sends the command to the L298N module to move the motors from the car.

The problem is that, while I’m able to define a combination of pushed buttons on the one side to a character, I don’t get any idea how I could say the other sketch that it should read and understand the meaning of the incoming character.

My currently attempt would be this code

while (digitalRead(CR))
    if(c == '1')   //vorwaerts //forward
    {
        digitalWrite(5,HIGH);
        digitalWrite(10,HIGH);
        digitalWrite(6,HIGH);
        digitalWrite(8,HIGH);
    }

but it’s pretty clear that this will not work like this.

The error message on the side of the receiver is:

‘c’ was not declared on this scope

Which is understandable, since it was only declared on the other sketch

Here is the code I’m using (I forgot to mention that I’m using the VirtualWire library, because it was said to me it’s easier to use for someone new)
Firstly the sketch of the Controller

#include <VirtualWire.h>
int LR = 7;
int LV = 8;
int RR = 2;
int RV = 3;

void setup()
{
  pinMode(LR, INPUT);
  pinMode(LV, INPUT);
  pinMode(RR, INPUT);
  pinMode(RV, INPUT);
  
  Serial.begin(9600);
  
 vw_setup(2000);
 vw_set_tx_pin(13);
}
void loop()
{
{
  if(Serial.available())
  {
    char a = Serial.read();

    if(a == '1')
    {
      vw_send((uint8_t *)a, 1);
    }
    else if(a == '0')
    {
      vw_send((uint8_t *)a, 1);
    }
  }
  {
    char b = Serial.read();

    if(b == '1')
    {
      vw_send((uint8_t *)b, 1);
    }
    else if(b == '0')
    {
      vw_send((uint8_t *)b, 1);
    }
  }
  {
    char c = Serial.read();

    if(c == '1')
    {
      vw_send((uint8_t *)c, 1);
    }
    else if(c == '0')
    {
      vw_send((uint8_t *)c, 1);
    }
  }
}

{
  while(digitalRead(LR) == LOW && digitalRead(LV) == HIGH && digitalRead(RR) == LOW && digitalRead(RV) == HIGH)//forward
  {
    Serial.print("a");
  }
  while(digitalRead(LR) == HIGH && digitalRead(LV) == LOW && digitalRead(RR) == HIGH && digitalRead(RV) == LOW)//backwards
  {
    Serial.print("b");
  }
  while(digitalRead(LR) == LOW && digitalRead(LV) == HIGH && digitalRead(RR) == LOW && digitalRead(RV) == LOW)//left forward 
  {
    Serial.print("c");
  }
  while(digitalRead(LR) == LOW && digitalRead(LV) == LOW && digitalRead(RR) == LOW && digitalRead(RV) == HIGH) //right forward
  {
    Serial.print("d");
  }
  while(digitalRead(LR) == HIGH && digitalRead(LV) == LOW && digitalRead(RR) == LOW && digitalRead(RV) == LOW) // left backwards
  {
    Serial.print("e");
  }
  while(digitalRead(LR) == LOW && digitalRead(LV) == LOW && digitalRead(RR) == HIGH && digitalRead(RV) == LOW) //right backwards
  {
    Serial.print("f");
  }
  while(digitalRead(LR) == LOW && digitalRead(LV) == HIGH && digitalRead(RR) == HIGH && digitalRead(RV) == LOW)//left forward & right backwards (up here it's just to have all possibilitys included)
  {
    Serial.print("g");
  }
  while(digitalRead(LR) == HIGH && digitalRead(LV) == LOW && digitalRead(RR) == LOW && digitalRead(RV) == HIGH)// left backwards & right forwards
  {
    Serial.print("h");
  }
}}

And now the one which is making me so much trouple:

#include <VirtualWire.h>

int LR = 7;
int LV = 6;
int RR = 8;
int RV = 9;
int ML = 5;
int MR = 10;
int CR  = 12;

void setup() {
 
pinMode(CR, INPUT);
pinMode(LR, OUTPUT);
pinMode(LV, OUTPUT);
pinMode(RR, OUTPUT);
pinMode(RV, OUTPUT);

  pinMode(13, OUTPUT);
  digitalWrite(13,LOW);

  vw_setup(2000);
  vw_set_rx_pin(CR); //!!!
  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(13,HIGH);
    }
    else if(buf[i] == '0')
    {
      digitalWrite(13,LOW);
    }
   }
  }
 }
  while (digitalRead(CR))
    if(c == '1')   //vorwaerts
    {
        digitalWrite(5,HIGH);
        digitalWrite(10,HIGH);
        digitalWrite(6,HIGH);
        digitalWrite(8,HIGH);
    }

I hope I didn’t forget any important information, but if I have, just saying it and then I will update this or write a new comment

Edit because of bad topic xD

On the receiving end, when you know that there is data available read the byte into a variable and then test the value of the variable.

Could you give me an example how this should look like? Or a link for a tutorial where I can see this?

look at the doc for your 433MHz RF modules and how to use them.

void loop() {
  {

What is this crap? A function body starts with ONE open curly brace.

Where IS c defined? The compiler is telling you that you MUST define all variables that you want to use. Where is c supposed to get a value?

What is this crap? A function body starts with ONE open curly brace

Thank you for the information^^

Where IS c defined? The compiler is telling you that you MUST define all variables that you want to use. Where is c supposed to get a value?

That was my question or atleast it should have been the question.
How can I define correctly the character, which the transmitter is sending?
Do I have to write

int c = 12

? (probably not)
I only know from where the Arduino has to read the signal and this would be pin 12 (pin 12 is defined as rx-pin, thanks to the VirtualWire library and a tutorial). In this pin would be the information that c (or another char) was transmitted. Currently this pin should been read through the command Serial.read .

How can I define correctly the character, which the transmitter is sending?

On the receiving end you need to declare the character that is being received. It does not need to have the same name as on the transmitter unless you want it to.

The easiest way is to declare it as a global variable at the top of the program

byte c;

Then you can use it later anywhere in the code.

Then you can use it later anywhere in the code.

That means that somewhere in the code you actually assign it a value.