Arduino Uno max memory at about 15% sketch(5KB)

So I made I made a program that only takes up 8KB of memory, after which it stopped working. Simply repeating the setup loop and not going into the main void loop. After looking online for a bit I found that the problem occurs when the program is larger than the space on the arduino. So I commented out several lines to lower the memory to about 5kb and it started working again. Pretty sure the issue is the memory but it should be able to be about 5x that value. This would mean that the bootloader is about 27 kb. Oh and Dmem is at 21% of total memory.

My code is as follows

//int XVal = A0;
int YVal = A1;
//int ZVal = A2;

//int sensor1 = 0;
int sensor2 = 0;
//int sensor3 = 0;

int midValue = 330;
int highValue = 330;
int lowValue = 330;

int error = 0;

int motor1 = 10;
int motor2 = 11;

//float prop = 1.0;
//float integ = 1.0;
//float deriv = 1.0;

void setup(){
  Serial.begin(9600);
//  pinMode(XVal, INPUT);
  pinMode(YVal, INPUT);
//  pinMode(ZVal, INPUT);
  
  pinMode(motor1, OUTPUT);
  pinMode(motor2, OUTPUT);
  Serial.println("{TABLE:Base|SET|error|" + String(error) + "|baseline}");
  Serial.println("{TABLE:Base|SET|proportional|" + String(error) + "|baseline}");
  Serial.println("{TABLE:Base|SET|integral|" + String(error) + "|baseline}");
  Serial.println("{TABLE:Base|SET|derivitive|" + String(error) + "|baseline}");
}

void loop(){


delay(300);

//  sensor1 = analogRead(XVal);
  sensor2 = analogRead(YVal);
 // sensor3 = analogRead(ZVal);

  if(sensor2 < lowValue){
  lowValue = sensor2;
  }
  else
  {
    if(sensor2 > highValue){
      highValue = sensor2;
    }
  }

  midValue = (highValue+lowValue)/2+10;

error = midValue - sensor2;

//printf("X %I Y %I Z %I", sensor1, sensor2,sensor3);
//Serial.println(String(sensor1) + "  " + String(sensor2) + "  " + String(sensor3));
//Serial.println(String(lowValue) + "L  " + String(midValue) + "M  " + String(highValue) + "H  ");
Serial.println(String(sensor2));
Serial.println("{TIMEPLOT|data|Pitch|T|" + String(sensor2) + "}");
Serial.println("{TABLE:Sensor|SET|Error|" + String(error) + "|amount off base}");
Serial.println("{TABLE:Sensor|SET|proportional|" + String(error) + "|proportional power}");

//Serial.println("#S|Proportion|[error]#");


  if(sensor2 < 340){
    analogWrite(motor1, 190 + error);
    analogWrite(motor2, 190 - error);
  }
  else
  {
    if(sensor2 > 360){ 
      analogWrite(motor1, 190 - error);
      analogWrite(motor2, 190 + error);
    }
    else
    {
      analogWrite(motor1, 0);
      analogWrite(motor2, 0);
    }
    
   }
  
  }

Unfortunately I believe I need the string operator for my final program, but this is good to know. Would using a board with a higher Sram fix this issue to allow a larger program to run for a finite amount of time? If so I may go ahead and upgrade my board.

When you say the string operator do you mean specifically how I am concatenating strings or the datatype string?

I can revise my code to get rid of the + operator, The piece of software I am going to be using to transmit to and from a file though transmits via string and sense I need to split the string into multiple values I would need to hold it in a string variable to split it up. Unless you can think of an arduino program that supports text file fetch commands.

I am probably going to need a more powerful micro even if I do find a way to get rid of the String class.

Oh and I appreciate you helping me out.

I meant on the receiving end, I could send a series of chars but I don't know if it would be possible to receive an array of chars from the software, I will have to figure out how to test this.

The software in question is Gobetwino and if there is a better software that is easier to use or better yet an arduino library, I would love to know.

I already wrote this post, but checked back today and found it wasnt here...

Replacing things like this:

Serial.println("{TABLE:Sensor|SET|Error|" + String(error) + "|amount off base}");

With things like this

Serial.print(F("{TABLE:Sensor|SET|Error|"));
Serial.print(error);
Serial.println(F("|amount off base}"));

will dramatically reduce memory (ie, SRAM) use.

F() macro puts the constant string into flash (rather than copying it to ram as it normally would be), and by splitting it up into those three print statements, you don't need a block of memory to put that data in.