Discover the best answers at Westonci.ca, where experts share their insights and knowledge with you. Get detailed and accurate answers to your questions from a community of experts on our comprehensive Q&A platform. Connect with a community of professionals ready to help you find accurate solutions to your questions quickly and efficiently.

this is my code for controlling a servomotor by Arduino Mega 2560
#include
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


Sagot :

There is no library included hence you are facing this error

What are the steps to resolve?

At the start of the program, you have missed adding the library file which is

#include<Servo.h>

The above one is the library you have to add

Also you have to attach the servo motor to the 9th pin of the Arduino mega

It is fine if you have added the servo.h library directly in your project

Kindly follow the above two steps it is because the serial port is not listening

Serial communication: Working with Arduino boards necessitates the use of serial communication and debugging. Simply put, serial communication is a method for the board to communicate with other devices, such as another computer, a peripheral, and so on. When discussing Arduino serial communication, it's also important to distinguish between its physical components (such as the Arduino's serial ports) and its software components (using the serial monitor in the Arduino IDE).

Thus serial communication helps in communicating with the devices attached to the board

To know more on serial communication follow this link:

https://brainly.com/question/28786797

#SPJ4