arduinomicrocontrollerservorc

my servo tries to go past its limit and wont stop until i unplug it, and force it into some normal posotion


I just bought 4 of these digital tower pro MG996R hi torque 180° servos for my Arduino. So, I put them into classical sweep test, however after some time. Without any reason it starts rotating clockwise until it reaches its limit, and tries to force itself past it, making weird buzzing noise(probably by the PWM) and consuming a lot of power. From 4 of them 2 do this and I have not yet tested the other 2, is there any explanation for it/how to fix it

Here is that code:

#include <Servo.h>
int pos = 0;

void setup() {myservo.attach(22);}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) {
    myservo.write(pos);
    delay(15);
  }

  for (pos = 180; pos >= 0; pos -= 1) {
    myservo.write(pos);
    delay(15);
  }

}

I tried using some blue tower pro SG90 microservo and it works just fine. are there some weird changes between those small blue servos, and other more robust ones, besidess power, speed, or voltage?


Solution

  • Ciao, You should consult, if available, the servomotor datasheet to check what are the necessary pulse width values to move the shaft to 0° or 180°.

    The Arduino Servo library have a minimum and maximum value defined by default, these can be set, for example, using the attach function. Default values are 544 microseconds and 2400 microseconds. Minimum and maximum of the attach(pin,min,max) function can also be useful to fine tune the movement of the servos. An interactive function could be created to more easily tune the servo positioning at its limits. If there are mechanical limiters in the servos, You should also check if they can be modified and if properly set.

    You find an use of minimum / maximum values in your code that I have modified (maximum value that I inserted is arbitrary).

    #include <Servo.h>
    int pos = 0;
    
    Servo myservo; # creating an instance myservo of Servo class
    
    // Consult servo datasheet for the pulse width necessary to move servo's shaft to minimum (0 degrees) and maximum position (n degrees)
    // attach function min and maximum values allow to fine tune servo positioning at 0 degrees and n degrees (90, 180, ...)
    int servo_min = 544 ; # servo minimum pulse  width in microseconds, default = 544 microseconds
    int servo_max = 2300 ; # servo maximum width, default = 2400 microseconds
    
    // void setup() {myservo.attach(22);}
    void setup() {myservo.attach(22, servo_min, servo_max);}
    
    void loop() {
      for (pos = 0; pos <= 180; pos += 1) {
        myservo.write(pos);
        delay(15);
      }
    
      for (pos = 180; pos >= 0; pos -= 1) {
        myservo.write(pos);
        delay(15);
      }
    
    }