Need help to factory reset by hardware

hi all.
i accidentally upload this sketch (bellow) to arduino mega 2560.
it loops every 1 sec and send out a message "hi there" to USB port, prolem is now i can't upload new sketch to the board via USB port because the board it using that port to send out message, i need to factory reset the board or clear sketch in boad by harware way.
any one can help ?.

this is the sketch is uploaded:

#include <SoftwareSerial.h>
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
Serial.print("hi there \r\n");
delay(1000);
}

You don't need to do anything special to overwrite that sketch. Close your serial monitor if you have it open, and upload a new sketch as normal.

In future please post code (and error messages) using code tags as described in https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966#posting-code-and-common-code-problems.

That won't stop it from uploading. The serial connection resets the board and it catches it in the bootloader way before the serial starts sending. However if you have the serial monitor open then sometimes that blocks you.

Hi, @vutan0306

What IDE and OS are you using?

Thanks.. Tom.... :smiley: :+1: :coffee: :australia: