averdude: stk500_send() Error

this is my code for controlling a servomotor by Arduino Mega 2560

#include <Servo.h>

Servo servo_test;

int angle = 0;

void setup()
{
servo_test.attach(9);
}

void loop()
{
for(angle = 0; angle < 180; angle += 1)
{
servo_test.write(90);
delay(15);
}

delay(1000);

for(angle = 180; angle>=1; angle-=5)
{
servo_test.write(90);
delay(5);
}

delay(1000);
}

and the error message I got was =>

Arduino: 1.8.1 (Windows 8.1), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

Sketch uses 3108 bytes (1%) of program storage space. Maximum is 253952 bytes.
Global variables use 167 bytes (2%) of dynamic memory, leaving 8025 bytes for local variables. Maximum is 8192 bytes.
avrdude: ser_open(): can't open device "\.\COM1": The system cannot find the file specified.

avrdude: ser_drain(): read error: The handle is invalid.

avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.

the selected serial port avrdude: stk500_send(): failed to send command to serial port
does not exist or your board is not connected

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer

Select the port of your Arduino from the Tools > Port menu. If that menu is grayed out or the port of your Arduino board is not shown then one of the following may be the cause:

  • You may need to install the driver for the USB-serial chip on your Arduino. Determine which chip is used on your Arduino and install the driver.
  • You may be using a charge-only or defective USB cable. Test your cable on another device to confirm that it works for data.
  • Using a USB 3.0 port on your computer may cause problems. Try a USB 2.0 port or use a USB 2.0 hub plugged into your USB 3.0 port.

thank you so much, man. so helpful! the problem was with the cable not being able to transfer data :))

I had a similar problem and found pert's advice helpful.

This worked for my Mega2560 (August 27, 2018): plug USB cable into Arduino and Windows 10 computer. Start Arduino IDE. At Tools>Port>, set check mark at the COMn that shows the Arduino microprocessor. Problem solved; upload works now.

My problem was the USB. Definitely choose a USB 2 port. The USB 3 port seems to always with a Programmer not responding error or an error indicating the port does not respond