Servo doesn't works correctly

Hello, I am trying to control the servo "hs-5645mg" with arduino but it doesn't works in all degree.

I have used the next code. With it, the servo changes it position

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

However, if I use any position like it doesn't move:

 myservo.write(0);//"myservo.write(25);"myservo.write(90);"myservo.write(0);

I don't know why happend it
Thank you

  • Did your servo ever work ?

  • Always show us a good schematic of your proposed circuit. Show us good images of your ‘actual’ wiring.

  • What servo power supply are you using, is there a common GND between the Arduino and the servo power supply ?

You should never post in the Uncategorised section.
It says so in the description of the section. Therefore I have moved your post here.

You might want to look at this How to get the best out of this forum before you proceed any further.

It happened it because it only had given it no time to get into position and if it was at position 0 when you started that line it was already there. Hence no movement.

If the servo is in "position 0" and you only give the servo the position command myservo.write(0), the servo will not move away and return.

Please post the full sketch where you try to move the servo to a fixed angle such as zero

I have tried with 5 servo with the same result.

#include <Servo.h>
Servo myservo;

void setup() {
  myservo.attach(6);  
    myservo.write(90); 
    delay(15); 

}

void loop() {}

I have tried with different start degree but it doesn't move.
The connections are:

Red wire: 5V arduino
black wire: GND arduino
Yellow Wire: pin 6 arduino

Thank you

Stall current from HS-5645MG High Torque Metal Gear 24T Digital Sport Servo | Hitec Radio Control : 2.4A

The Arduino will not supply anywhere near that much current from its 5V pin. Not even half that.

If you have only one position in the sketch, the servo will not move after arriving at the first position.

Hi Again,

I think that the problem is the library.
I have modified the schematic. I supply 5v since powerbank(3A output) to the servo and I wire the GND and the yellow pin to arduino (PIN 3).

I will try to explain better:

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

If I use the code above, the servo moves from left to right and right to left, but not to all degrees. I saw that the servo does not move to 0. It stops at about 20 degrees. At the other end the servo stops at 160 and does not go to 180.

On the other hand, if I use the following code, the servo does not move no matter what degree it starts at and what degree is chosen.

#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 9 to the servo object
   myservo.write(90); //servo is in the 0 degree
    delay(15);                       // waits 15ms for the servo to reach the position


}
void loop() {}

In conclusion, the servo only move if I use a "for" and It doesn't move in all degree

Thank you

When you attach() the servo it moves to its default start position, which is 90 degrees. Then you write(90) to it which tells it to move to 90 degrees, but it is already there. Why do you expect to see it move ?

Try this

#include <Servo.h>
Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

void setup()
{
  myservo.attach(3);  // attaches the servo on pin 3 to the servo object
  delay(1000);
  myservo.write(150);
}

void loop() {}