Servo sg90 doesn't turn back

Hi,

I have an Elego Mega 2560 and a servo motor (Tower Pro SG90).

My problem: my servo moves only in one direction and it doesn’t turn back. I want to perform a movement from 0° to 90° and then from 90° to 0° again.

At the moment, I have done the sweep tutorial and also tried to power the servo with some batteries. Oddly, when i power the servo with the 5v arduino pin, it turns anticlockwise and when i connect it to the batteries, it goes clockwise.

Here are the links to the youtube videos:
Servo powered with arduino
Servo powered with batteries

And here is the code I used:

#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
  }
}

Thank you for your help!

Turin

Hi, Probably servo power problem..

Also those servos often don't go all the way from 0..180.See This Page

Try this code:

Let us know what happens...

terryking228: Hi, Probably servo power problem..

Also those servos often don't go all the way from 0..180.See This Page

Try this code:

Let us know what happens...

Didn't work :confused:

I also tried reducing the movement between 30 and 70 degrees with:

define ServoMIN 30

define ServoMAX 70

Still the same.

For the power issue I've tried using an independent source and had the same result.

Hi, OK, starting to look like the servo. ANY other servos you can test with??

terryking228: Hi, OK, starting to look like the servo. ANY other servos you can test with??

Uhmm i'll try to get a new one and comment back.

Thank you for your help Terry!