Arduino Mega clear sketch or serial flood problem

I have been searching for nights about how to erase all sketches from an arduino mega board.

I found this old thread http://forum.arduino.cc/index.php?topic=72323.0

but I tried to upload empty sketch and it is not working. I also tried the un-plug/plug USB and reset button and no luck at all.

In summary, my problem is that I have been uploading many sketches for my little project which runs a number of continuous servos. see my thread here http://forum.arduino.cc/index.php?topic=384766.0. But every time I upload an updated sketch, the servos keeps rotating in random, as if they are receiving left over of previous signals.

I am thinking may be if I create a new sketch with instructions to flush the serial data totally then it may re-fresh the program. Does anyone have link to such example code?

I stumbled in this and going crazy -

Thank you for the help in advance.

zakim: but I tried to upload empty sketch and it is not working.

What does this sentence mean? Are you able to successfully upload any sketch to the board? How about if you remove all stuff connected to the pins of the board and unplug shields, and just connect the board to the computer via USB and upload a sketch?

Thanks for the links to previous topics. I think you are still in the same trouble as here : http://forum.arduino.cc/index.php?topic=384766.0

Do as dmjlambert wrote, remove everything, and upload a simple sketch, for example the blink sketch.

I often use this for a test:

void setup()
{
  Serial.begin(9600);
  Serial.println("Hello");
  Serial.println(F(__DATE__));
  Serial.println(F(__TIME__));
}

void loop()
{
}

The date and time show the compilation date and time, so I can tell if it is really the sketch I have just compiled.

Your servo motors seem to have a lot of problems. That has often to do with lack of power or a missing GND connection. Use a power supply that can deliver 1A per servo motor. You have to give a lot more information on your circuit, power supply, servo motors, and so on, for us to give good information how to solve it.

Thank you all for your feedback.

I am attaching the full circuit of the project. As some have mentioned, there is probably power pulse going on driving the motors even though I have uploaded an empty sketch to overwrite previous program.

I also noticed that the strange behavior of the servos running starts to happen after continuing the connection of servos 4, 5 and 6. !!!

The Arduino board 5V pin can not be used to power servo motor(s). You need to test the sketch without the servo motors, and if you do connect the servo motors, they need a seperate power supply.

I will say it again: The Arduino 5V pin can not power a servo motor. I know that there are examples and tutorial that do that, but it’s not okay. A servo motor can require 500mA when it starts to turn, it can even be a peak current of 1A.
Even for just a small test, you should not power a servo motor with the Arduino 5V pin.

Hi Koepel,

I tested the sketch on one servo, also upload the sketch without problems.

I am using an external power supply adaptor (see sketch). The adaptor is 9-12V, with output 350mA Max. I can buy another adaptor with output (500mA to even 1000A) if that is the problem!!!

http://powerhouse.com.ph/product_info.php?products_id=2180

Question (1): so is the circuit diagram correct?
Question (2): how do I connect the power to servos without the 5V pin?

The Arduino 5V pin can not supply enough current for one servo motor. Don't do that.

When you use an external power supply of 5V or 6V to power the servo motors directly, then you have to connect the grounds. If the power supply of 350mA is used to power the servo motors directly, then the 350mA is barely enough current for one servo motor. A 9V battery is too much voltage and too little current.

Please do not use the Arduino 5V pin to power a servo motor.

... thanks a lot... I will try to power the servos with external 5-6V battery supply, and see how it goes...

... so I found a "quick-and-dirty" working solution. I assigned the Pins(2 to 7) that are connected to the servos, a Low voltage. Just like the one found in the LED "Blink" example.

STEPS: 1) Decaled [int ledPin2 = 2;] six time for all the six pins (2-7) 2) in the setup loop, I specify [pinMode(ledPin2, OUTPUT);] six time for all the six pins (2-7) 3) I assign [digitalWrite(ledPin2, LOW);] six time for all the six pins (2-7). This is the solution as it sets the voltage LOW and therefore all servos stops.

4) Then I implement my project program/logic.

So far it is working fine and will share any issues if found.

Thank you all