Sunday, January 15, 2017

Servo Motor and Arduino Basics




Arduino Sketch:

#include <Servo.h>

Servo myServo;

int servoPin = 9;

// the setup routine runs once when you press reset:
void setup() {
  // initialize the digital pin as an output.
  myServo.attach(servoPin);
}

// the loop routine runs over and over again forever:
void loop() {
  //Moving forward in the increments of 45 degrees, upto 180 degree
  myServo.write(45);
  delay(1000);
  myServo.write(90);
  delay(1000);
  myServo.write(135);
  delay(1000);
  myServo.write(180);
  delay(1000);

  //Moving backward in the deccrements of 45 degrees, upto 0 degree
  myServo.write(135);
  delay(1000);
  myServo.write(90);
  delay(1000);
  myServo.write(45);
  delay(1000);
  myServo.write(0);
  delay(1000);

}

No comments:

Post a Comment