Problems with Tower Pro SG90 servo

Hello, and thanks for previous help on this forum.

I have a problem driving a new SG90 servo with the standard sweep sketch included in the examples.

Connections -
I originally tested it directly connected to the Arduino Uno as per the tutorials but found this is a bad idea and causes problems. I then used a LM7805 regulator with cap on the output connected to a 14v tool battery to supply the servo, and commoned the ground to the Arduino.

The servo performed exactly the same as it did previously.

Problem-
The servo goes at full speed to a start position, then rotates anticlockwise exactly 180 degrees at a slower pace as it should. Then reverses and travels 260 degrees clockwise past the original start position at a slow pace, then accelerates to full speed round to the start position (approx 280 degrees) still clockwise.

I don't think it is a power issue, but may be a pulse width driving issue causing an overshoot in one direction, or a problem with the servo finding the datum position.

What I have tried-
I have programmed the servo to go to specific degrees and stay there. It works for all angles except 0-10 degrees. If it is told to go between 0-10 it will keep rotating.

As a work-around I have programmed it to sweep from 10 degrees as a start position to 190 degrees and return. It does this very well and is a work-around for the 0-10 problem blind spot.

I would be interested in any fixes or knowledge on why it does this. It is only to mount the ultrasonic module onto for a sonar style project which makes the small size ideal.

I have found a post with problems driving the SG90 and it seems to point to the servo library using "standard" limits for endpoints. HERE

He quotes

Tower Pro SG90: 500us CCW 1500us CW
Tower Pro MG91: 710us CCW 2290us CW

Do I edit the servo library (Which could mess up future projects) or edit the program to suit the servo used?

Thanks.

I can't imagine that the towerpro sg90 has specs that far away from the standard.
They are designed to work with a standard RC receiver, and it will have a pulse width of about 1000us to 2000us.
The specs I have seen state 500-2400us, so it is allows for a slightly wider range.

What I have tried-
I have programmed the servo to go to specific degrees and stay there. It works for all angles except 0-10 degrees. If it is told to go between 0-10 it will keep rotating.

What do you mean keep rotating?

Can you post code for this?

To change the endpoints you just need to set new endpoints when you do the servo.attach. See Servo - Arduino Reference

But I'm not convinced that's problem. Apart from anything else I've never seen a (working) SG90 that will travel anywhere near 280 degrees. Have you tried more than one servo?

Steve

Thank you both for the answers.

By keep rotating I mean I programmed it to go to one set point in the setup and commented out all of the loop and just kept the delays in there.
The set points that work are anywhere up to 360 but not between 0-10 degrees. If told to go to say 5 degrees the servo will rotate in one direction continuously without stopping. There are no end stops on this servo. Good job too!

Thank you for the attach syntax. I will try out values to see if I can get it to work properly with the 0-180 standard sweep program, then note results here.

Richie_asg1:
There are no end stops on this servo.

This confuses me.
I can find no reference that indicates that the SG90 is a continuous rotation servo. Did you modify the servo? A standard servo should not rotate continuously. If yours does, I suspect it is broken.

[code/]* Sweep
 by BARRAGAN <http://barraganstudio.com>
 This example code is in the public domain.

 modified 8 Nov 2013
 by Scott Fitzgerald
 http://www.arduino.cc/en/Tutorial/Sweep
*/

#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 @@@@@@@@ CHANGE THIS TO ANGLE @@@

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

I am changing int pos=0 (Where the @@@@@ are) to a set angle to see what the servo does.

When told to go to 90 I can set the horn on the servo to be at the 12 oclock position.
When told to go to 180 the servo moves anticlockwise to between 7 and 8 oclock position.
When told to go to 0 the servo rotates clockwise continuously, but slows each time it passes between 4 to 5 oclock position, then speeds up again.
When told to go to 10 the servo moves to 4 oclock position.

I have got it working with the following additions to the attach servo command.

myservo.attach(9,880,2120)

This seems to set the end points correctly without over-run.

They may need a little tweak to get exactly 0-180 degrees movement but is pretty close to spot on.

Thank you for your help in suggesting this is the problem Slipstick.

Richie_asg1:
When told to go to 0 the servo rotates clockwise continuously, but slows each time it passes between 4 to 5 oclock position, then speeds up again.

I think your servo is broken.

Very likely. It is brand new but that counts for nothing. Seems to work ok now with the limits reset.

At least I have learnt something about servos!

If it is not mission critical, then you can keep using it for continued experimentation.

But I use a lot of servos for my radio control planes. When one misbehaves, it gets replaced. Better to replace a $15 servo (sometimes a $4 servo) than to lose the whole plane.

Very true. In many fields it is better to pay for quality parts if they are critical or difficult to get to. But this is just a cheapie to learn with, make a sweep sonar and learn the ropes.
As it was just operating in free air I thought it could cope with that.

I don't think I would recommend the SG90 for anything other than table toys. It's certainly at the bottom end of the price range.

SG90s work well in quite a few of my model aircraft. There are many worse small servos provided you get genuine TowerPros and not the really cheap clones.

But even then what you lose with cheapish servos is mainly quality control. You just have to expect that the odd one will be DOA or as in your case peculiarly faulty, with the feedback obviously not working as it should.

Steve

I'm thinking that you don't have an authentic Tower Pro SG90 or it may be broken as previously noted. I have some sg90 type servos that are NOT made by Tower Pro and they all behave erratically. Also, they are not limited to 180 degrees; they will sometime rotate 360 degrees, but they will not have any continuous rotation. Buy an authentic Tower Pro SG90 and I think you will get proper operation as long as there's not a sketch problem.