Programming Examples
Arduino program to connect with Servo Motor
Create a Arduino Program to Interface with Servo Motor
Solution
#include <Servo.h>
// Create a Servo object
Servo myservo;
void setup()
{
myservo.attach(9);
// Optionally, move the servo to the initial position
myservo.write(0); // Move to 0 degrees
Serial.begin(9600);
}
void loop()
{
for(int a=1;a<=180;a=a+10)
{
Serial.println(a);
myservo.write(a);
delay(10);
}
delay(1000);
for(int a=180;a>=0;a=a-10)
{
Serial.println(a);
myservo.write(a);
delay(10);
}
delay(1000);
}
Output