Weird problem that is also unexpected. So I was working on a project, of which I can’t share the code, but I ran into an issue. Whenever I try to use servos they just end up spinning continuously despite them being 180deg servos. I checked my connections (grounds connected!), I’ve used different boards, I bought new servos from different sources, tried diff types of servos, I’ve updated the ide, I’ve tried the standard sweep code, I’ve tried mechanically limited servos (they just push up against the mechanism in the same direction), all the same result which is spinning continuously or up to the mechanical limit in the same direction.
This started happening when my old computer broke and I bought a new one. I don’t have another computer as our work laptops are too locked down to allow an Arduino to show connected. I’m getting to the point I’m positive it’s a computer or IDE issue. If you look hard enough, there are other people having the same issue with the same troubleshooting result. The only fix I have found people mention is using another computer which seems to work. Here is an example however this person doesn’t seem to have found a solution.
I know it’s quick to suspect incorrect connections or programming but that is not this. The only time I get a different result is when I start specifying high times on the “myservo.attach(9, XXXX, XXXX)” of which I get slight movement correctly then still ends up spinning continuously. This is part of the reason I suspect the code the board is getting is not the correct code for what is specified in the IDE. Keep in mind this is happening accross multiple boards with the same connections. I’m posting this as there is probably someone, somewhere, that has figured this out.
Standard sweep code that results in endless spinning on 180 degree servo comes from the standard servo.h library, only thing that is changed is pin to 9 or A0, depending on board.
Standard servos do not (cannot) spin continuously unless they are damaged or modified. Their behavior has nothing to do with the PC that the Arduino is connected to
As a matter of interest, how are the servos powered and which Arduino board are you using ?
No problem! Please post some code that demonstrates the issues you’re encountering, and make sure to use code tags for clarity when sharing it. Additionally, include an annotated schematic showing all connections, including power, ground, power sources, and any external components. Be sure to also include links to technical information on each of the hardware items. This information will help in diagnosing and solving the problem effectively.
Agree with @UKHeliBob, only continuous rotation servos can rotate continuously. These are not 180 degree servos, even if that is what the label says. They have been modified or damaged.
I have watched the MG90S spin continuously, over 10 diff ones because I keep grabbing a fresh on when I make a change. The only ones that don’t spin continuously are the mechanically limited ones. I’ve disassembled the MG90s, there is nothing keeping it from spinning 360 other than feedback from a potentiometer that is supposed to stop it. But they can spin continuously.
I know another thought may be that these are continuous servos, keep in mind I have the same issue with larger mechanically limited ones but they just stop at the mechanical limit and push against it without ever sweeping.
These servos are powered by USB C, which directly powers the servo and the board is powered in parallel. The project board is an Arduino pro mini however I have tried with a Nano and Uno running a servo programmed from the same computer / ide, and get the same result. Here is how the nano is setup
Here is the sweep code that shows the issue. I tried to post a video of the servo spinning continuously however it did not let me. If you can recommend a file hosting site I can use without too much trouble? I’m also including pictures of two boards setup electrically the same where the issue occurs. I have tried even more combos than this. Also, I tried servo testers, and the servos work fine on the servo testers.
#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
}
}
I change the pin to pin 9 for the pro mini and A0 on the nano. Same result. The servo is powered from the USBc male. Not the pro mini did have a light sensor which was part of the original project however it has been removed as part of the troubleshooting process.
If the servo rotates continuously in the same direction when you run that code then it is damaged. If it speeds up, slows down and changes direction then it is a continuous rotation (so called) servo which is not a servo at all
I can understand - however why would the same issue happen on the mechanically limited 20kg servo I have, only instead of sweeping, it runs up against the mechanical limit and holds there. If the issue were the servos only, this 20kg 180deg servo should sweep with the sweep code.
I advise also to check the link where other people have had this issue (I have found others as well) and the only fix was uploading from another computer.
Currently I have 2.3.4-nightly-20241128. While troubleshooting I updated, I used to have a version at least a year old. Even after updating, the issue persists.
I do have a DMM as well as an oscilloscope.
Are you able to judge based upon my previous oscilloscope readings if I am getting the correct amount of high time for MG90S servos (or really any servos). At one direction I am seeing a high time of 9.4ms on the signal pin… that seems way out of bounds to me.
@TomGeorge , let me get this setup real quick , should I use sweep code for this test(where the signal will constantly change and potentially change our readings)? Or potentially just force it to one direction and consistent signal?
That way the controller uses one USB supply and the servo the other, as long as there is a gnd and signal connection between controller and servo, it will work.
Ideally an AA pack of 4 batteries would be better for the servo.
What is the current spec of your servos?
That is very important.
Interestingly, I rewrote the sweep code to just set the servo to “0” position (code to follow) and this is the first time in a while the servo hadn’t resulted in spinning aimlessly. It is sitting still at some position, unsure if it is “true” zero though. Appears high time is roughly 2.2ms, which still seems high from my understanding. I’ll try other positions as well and report back.
@TomGeorge - I can’t tell you how much I appreciate your help.
To answer your questions about the usb supply, I only program from the USB on the board. After that I immediately remove that connection, attach the servo on the DuPont line, then I power the project from the male usb c cable soldered to the board. The true project board is the pro-mini, however the nano was setup just to see if the issue was board related, however I got the same result.
Here is the code from the “0” position test I mentioned a few replies up which resulted in 2.2ms high time roughly. Showing 454hz but I’m doubting that
#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() {
myservo.write(pos); // tell servo to go to position in variable 'pos'
}