Serial communication between 2 arduinos

So I want to communicatie between 2 arduinos. So I have connected the 2 arduinos using the gnd, tx and rx using the UNO.

Communication works, if I serial.write something it will get printed into the other arduino. Now I am having alot of difficulty with setting variables.

Senders code

char mystr = "Hello"; 

void setup() {
  // Begin the Serial at 9600 Baud
  Serial.begin(9600);
}

void loop() {
  Serial.println("test"); 
  delay(1000);
}

The sending code sends a char, the receiving code needs to put this into a variable.

Receiving code

void setup() {

  Serial.begin(9600);
  Serial.println("Is this on?...");
}


void loop() {

  if (Serial.available() > 0) {
    
    char var = Serial.read();
   // tijd = Serial.parseInt();
   String var1(var);
    Serial.println(var1);
  }
}

Output

Is this on?
t
e
s
t

When it prints it will print 1 letter at a time but I don't want that. It needs to print "test".
How can I do something like that?

Take a look at Serial input basics - updated

Don't use println; use print instead. For you to figure out the difference :wink:

Learn not to use String (capital S). It's a potential recipe for difficult to find bugs due to memory leaks. Your usage is totally redundant, you could in your current code just as well print var.

parseInt is a blocking function and that might bite you in the future; don't use it.

And follow the link above, read it and understand it. It gives you everything you need avoiding the possibility of the above mentioned problems.