avrdude: timeoutavrdude

Hello, I know how to do basic troubleshooting in Arduino. But this certain case, I can't understand. Please see my attachments....

INFO:

  1. I'm using MacBook Pro for burning the codes into the arduino. I am using Arduino Mega 2560 R3. Authentic and working 100%

  2. Sketch1 (filename:_5switches_working.ino) -- This one works. I can upload it to the board easily. It has 5 float switches.

  3. Sketch #2 (filename: sixswitches_TIMEOUT.ino) -- This one doesn't work. It won't upload to the board. It has 6 float switches.

What I already did:

  1. Modify the codes in sketch #2, to make it small in size and eat smaller RAM as much as possible.
  2. One of the steps I did is erasing some of my string array.

Here are the information of the sketches:

// revised Sketch#2:
//Sketch uses 38,750 bytes (15%) of program storage space. Maximum is 253,952 bytes.
//Global variables use 3,992 bytes (48%) of dynamic memory, leaving 4,200 bytes for local variables. Maximum is 8,192 bytes

// six sensors:
//Sketch uses 39,398 bytes (15%) of program storage space. Maximum is 253,952 bytes.
//Global variables use 4,816 bytes (58%) of dynamic memory, leaving 3,376 bytes for local variables. Maximum is 8,192 bytes.

// 5 sensors:

//Sketch uses 38,354 bytes (15%) of program storage space. Maximum is 253,952 bytes.
//Global variables use 4,184 bytes (51%) of dynamic memory, leaving 4,008 bytes for local variables. Maximum is 8,192 bytes.


Lastly: the error in Sketch #2 upon uploading the codes is this:
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk50..........

sixswitches_TIMEOUT.ino (15.9 KB)

_5switches_working.ino (13.6 KB)

solved: I just debug the whole code. What I did was I tried to add one function at a time in the _5switches_working.ino for the 6th switch. After adding a certain function, try to upload it. If succeeded, proceed to next adding of function. I think the error was from the 6th char array.