Skip to main content

How To Run a Servo Motor Using Adriuno



 How To Connect a Servo Motor To Adriuno
                                                                                           Basically servo motor is having three pins positive(red),negative(black),Feedback(yellow) , so easy positive goes to 5V and negative goes to some ground pin  And feedback goes to any digital pin in ardiuno board i would prefer 9th pin


·         Red(positive)         -5V
·         Black(negative)     -ground(gnd)
·         Yellow(feedback) -9th pin(digital)


And the program for servo motor is in ardiuno ide software in (file=>examples=>servo=>sweep)
If you don’t have a ide software don’t worry here program for you



#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}



That is the program for sweeping the servo motor if the program is runs 180 degree in clockwise and rotates 180 degree in counterclockwise simultaneously



Thanks for visiting our site

Comments