Servo Motor Spinning Continously

Hi all, I'm currently encountering an issue with my Arduino Uno in which my servos rotate continuously despite being coded otherwise. I do not have a continuous servo. My setup is described as follows:

Arduino Uno R3
Servos: 1x ZOSKAY 25KG Servo Motor (https://www.amazon.com/ZOSKAY-Waterproof-Standard-Digital-Control/dp/B07GLMDJQ7)

Yellow ->Control Pin 9 (PWM)
Black -> POWER GND
Red -> POWER 5V
Servos are receiving power from the Arduino board, which is connected to PC via USB.

My code is the simple code provided by Arduino:

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

Upon execution, this code rotates the servo motor continuously in a clockwise fashion without stop. Interestingly, if I reduce the code to simply the myservo.attach(pin), upon connecting the servo it immediately begins rotating.

My hypothesis is that the servo is not speaking the Arduino's current language (frequency), but am unsure. Any help would be much appreciated!!

Do you mean your servo motor is going CW then CCW etc. ?

If so you are telling it to do this in your sketch.

You can also try this code

#include <Servo.h> 
// Declare the Servo pin 
int servoPin = 9; 
Servo Servo1; 
void setup() { 
   // We need to attach the servo to the used pin number 
   Servo1.attach(servoPin); 
}
void loop(){ 
   // Make servo go to 180 degrees 
   Servo1.write(180); 
   delay(1000); 

   // Make servo go to 0 degrees 
   Servo1.write(180); 
   delay(1000); 
}

:thinking:

Sorry my mistake but their is -180 for reaches to 0 degree

#include <Servo.h> 
// Declare the Servo pin 
int servoPin = 9; 
Servo Servo1; 
void setup() { 
   // We need to attach the servo to the used pin number 
   Servo1.attach(servoPin); 
}
void loop(){ 
   // Make servo go to 180 degrees 
   Servo1.write(180); 
   delay(1000); 

   // Make servo go to 0 degrees 
   Servo1.write(-180); 
   delay(1000); 
}

My apologies for the potential misunderstanding, thank you for trying to help!

The servo begins rotating CW and does not stop. Both the code I wrote and the code you wrote produce this result.

New thoughts: the servo library is 50Hz and the servo claims to be rated to 50-300Hz. Is it possible the PWM is wrong?

Then your servo is not a regular servo motor.

It must be a continuous servo.

If my code isn't working in your setup then something wrong in your side
Cause I had run easily :v:

I had thought this was the case earlier and tried running code that would work for a continuous servo (0 full reverse speed, 90 stationary, 180 full speed). Unfortunately this produced identical results.

I've tried to take this code line by line to identify potential issues. I do not have much work with arduino servo control, but I find it exceptionally odd that simply running this code, and then connecting the pins, causes the servo to continuously rotate:

#include <Servo.h> 
// Declare the Servo pin 
int servoPin = 9; 

Servo Servo1; 
void setup() { 
   // We need to attach the servo to the used pin number 
   Servo1.attach(servoPin); 
}

void loop() {}

This is what makes me think there is something else going on..

A continuous servo will only stop if the servo angle signal is somewhere around 90°; you’ll need to tune it with a potentiometer or similar technique.

Gotcha, thanks for this knowledge. I will make in attempt early tomorrow and update here. Thanks!

That is NOT how you get a servo back to 0°. You tell it to go to 0°:
Servo1.write(0);

Hi all, providing an update.

I ended up connecting a LiPo battery to a 5V BEC and a 6-Ch receiver and have been able to control these servos perfectly fine using an RC aircraft controller. Upon powering with the controller, these servos move perfectly to their zero positions and I am able to control them to 90deg of operation (as standard for servos in aircraft applications, +/- 45deg)

I am under the impression as of the moment that there is something wrong with the Arduino, as it is clear that it was not communicating properly with the servos. I will have the opportunity to test with a new Arduino shortly and will update again. Any other ideas are welcome!!

Yes, test with known good example sketches instead of your sketches.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.