Programming Examples

Arduino program to connect with Servo Motor


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);
    
}
▶ RUN

Output/ Explanation:


Latest Current Affairs 2025 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad