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);
    
}
Output


Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2024 Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz