Coding Help

It is not a good idea to use Strings with Arduino. They cause memory problems.

Use character arrays instead, and post your code properly, so it looks like this similar program using character arrays;

char message[21];  //20 characters plus zero terminator
int x=0; //array index

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect
  }
  // send an intro:
  Serial.println("Code Initialized");
}

void loop() {
  if (Serial.available() > 0) {
     
      message[x] = Serial.read(); // add incoming characters to the array
      x++; //increment index
      message[x]=0; //terminate character string
    }
    if ( strlen(message) == 20 ) { //if 20 characters have been read and stored, print the string
            Serial.println(message);
            x=0; //start over from beginning
            message[x]=0; //empty message
    }
   }