Serial forces restart while on external power

Hi! I've run into this problem while using an Arduino Mega, a pH reading stamp, and an LCD (all communicate via serial). Basically, the pH stamp gets its measurements, and by SerialEvent, it send it to the Arduino, which then prints the readings to the LCD. This works fine, but at random times, the Arduino restarts.

I've read a few pages about this auto-restart issue, and the two common fixes I've seen are to either disable DTR on your computer, or to physically break the connection to the reset pin (cutting a trace or removing a capacitor). The thing is that I'm running the Mega on an external 7V input, so I don't see the DTR-fix working for me. And as much as possible, I want to leave the second option as a last resort.

Is it possible that something in my code can force a restart of the Arduino?

This bit is outside the loop:

void serialEvent1() {
  char inchar = (char)Serial1.read();
  temppH2 += inchar;
  if(inchar == '\r' && Menu=="0") {
    armCond = true;
  }
}

void serialEvent2() {
  char inchar = (char)Serial2.read();
  tempCo2 += inchar;
  if(inchar == '\r' && Menu=="0") {
    armCond = true;
  }
}

void serialEvent3() {
  char inchar = (char)Serial3.read();
  tempCo1 += inchar;
  if(inchar == '\r' && Menu=="0") {
    armCond = true;
  }
}

This one is within the loop (was using softwareSerial, so I couldn't use a Serial Event anymore):

if(armCond==true && Menu=="0" && Main==false) {
    lcd.setCursor(12,1);
    lcd.print(tempCo1.substring(0,tempCo1.indexOf(',')));
    //lcd.print("     ");
    lcd.setCursor(12,2);
    lcd.print(tempCo2.substring(0,tempCo2.indexOf(',')));
    //lcd.print("     ");
    tempCo1="";
    tempCo2="";
    
    lcd.setCursor(12,5);
    lcd.print(temppH1);
    //lcd.print("     ");
    lcd.setCursor(12,6);
    lcd.print(temppH2);
    //lcd.print("     ");
    temppH1="";
    temppH2="";
    
    armCond=false;
  }

while(Serial0.available()) {
    char inchar0 = (char)Serial0.read();
    temppH1 += inchar0;
    if(inchar0 == '\r' && Menu=="0") {
      armCond = true;
    }
}

btw, '\r' is the carriage return the stamp sends once it has data ready to send

Thank you very much for your time :)

Try to disable the auto-reset passing a 120 ohms resistor from VCC to reset pin. From the code you post I can see possible problem but one of possible reasons is you using an array with a fixed size and write over that size wrongly but mistake.This will produce memory leak and touch in sensitive parts of memory causing a reset.This is just a tip, post all your code

I see, thank you very very much, Hugo!

Actually, I've been trying to monitor the reset pin, and no pulse registers on the oscilloscope when the Arduino restarts. And the full code is quite horrendous to look through for just a small issue like this, so I'll take your advice on the fixed array issue and see if that helps.

Once again, thank you!

P.S. are there any pages where I can read up on how memory flow triggers a reset on the MCU?