Problem with serial communication

Unsigned_Arduino:
Let's try this then...

Maybe I have not understood your code but it looks to me like it blocks for up to 5 seconds while waiting for a response.

That may be OK for a particular project but it is hardly a general solution.

My approach, as an extension of the 3rd example in Serial Input Basics would be something like this

sendTheData();
dataSentMillis = millis();
waitingForReply = true;

if (newData == true) {
   waitingForReply = false;
}
if (waitingForReply == false and millis() - dataSentMillis >= timeoutMillis) {
   // waiting too long - do whatever
}

This way the Arduino can continue doing other things while waiting for the response

...R