Sunday, 4 January 2015

SG90 servo wiring

You might be bit confused about wiring up your TowerPro SG90 but don't worry here is the solution.
The brown wire is ground (-) and the middle one seems like orange or red that's (+) vcc and yellow or kind of orange that's for data/signal.

You can try the sketch below or get it from Arduino site.

#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(3);  // attaches the servo on pin 3 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(5);                       // 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(5);                       // waits 15ms for the servo to reach the position
  }
}

Note: if you don't know what sg90 servo motor is, then her is a video for you to watch.

Have a good time.

No comments:

Post a Comment