Servo only updates every few seconds

Dear community!

I am new here and have a problem with the control of a servo. It’s a Miuzei 9g motor, a quite common one i think. I can steer it to every specific position with servoObj.write, and also with servoObj.writeMicroseconds (it works in a range of 500-2500 with a dead band of 5).
However, as soon as i try to evoke any kind if continuous movement, it behaves completely unexpectedly. It only updates very few seconds! and then jumps wide ranges. Adjusting delays in between doesn’t help. I can steer it with tons of single commands perfectly fine, but it doesn’t work as soon as it’s position gets declared by any kind of variable changing values. Reading the variable, however, it behaves exactly as expected.

code:

#include <Servo.h>

Servo rocketServo1;

int angle;
int pos = 0;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);

  rocketServo1.attach(9);

  angle = 500;

  Serial.begin(9600);  // open a serial connection to your computer
}

void loop() {

  //-> problem: servo only updates from time to time. every few seconds in this case. The angle runs through as expected.

  Serial.print("angle: ");
  Serial.print(angle);
  Serial.print('\n');
  
  angle += 1;
  rocketServo1.writeMicroseconds(angle);

  if (angle > 2500) {
    angle = 500;
    digitalWrite(LED_BUILTIN, HIGH);
    delay(500);
  }
  digitalWrite(LED_BUILTIN, LOW);

  delay(15);
}

In the photos attached you can see the warping jumps it makes, and it takes around 2-3 seconds to make them. The actual angle value runs far quicker, and even with a delay of 100ms the servo doesn’t make it.



All the best
Simon

@simon_fischer
You should have a separate 5V supply for the servo. Don't power it from the Arduino.
Delay(15) should be delay(25) or longer

thanks a lot. I’ll try that. So what actually happens to the servo when there is not enough power? Is it that the servo’s controller decides to abort the movement?

From my electronical understanding, it shouldn’t make much of a difference when it’s only about moving one servo. I have measured the voltage and it hardly drops when moving the servo. Also, one servo hardly takes up current.
Interestingly, with very specific for loops and very specific delays it works extremely smoothly. But changing it a little and it doesn’t.

I would not say 350mA or higher is hardly any current.

Also, incrementing it in 1u steps probably will not work. 5u to 10u steps should be the smallest you should do.

The delay between steps should be 25ms or more.

thanks a lot!

Pg 17
https://docs.arduino.cc/resources/datasheets/ABX00087-datasheet.pdf

Don't use the Arduino to power servos

It acts in the way you described. Worse, you risk damaging your Arduino.

You are welcome
Have Fun!

i have now connected it to a stable and precise 6v power supply and grounded it. Also, i changed the delay to 25 ms, and the angle microseconds to 10. Still, it dies the same thing. varying the microseconds changes it a little, but doesn’t resolve it. Also the simple .write function doesn’t help.

video:

Looks OK to me.
What were you expecting it to do?
Post your new code.

Hopefully you did not damage your Arduino. Use a volt meter and check the 5V and 3V3 outputs to be sure they are correct. Here is something that may help:
Gil's Crispy Critter Rules, they apply to processor hardware:
Rule #1. A Power Supply the Arduino is NOT!
Rule #2. Never Connect Anything Inductive (motor, speaker) to an Arduino!
Rule #3 Don't connecting or disconnecting wires with power on.
Rule #4 Do not apply power to any pin unless you know what you are doing.
Rule #5 Do not exceed maximum Voltages.
Rule #6 Many will not power a transmitter.
LaryD's Corollary's
Coro #1 when first starting out, add a 220R resistor in series with both Input and Output pins.
Coro #2 buy a DMM (Digital Multi-meter) to measure voltages, currents and resistance. Violating these rules tends to make crispy critters out of Arduinos.
Hint: It is best to keep the wires under 25cm/10" for good performance.

What happens when you run the Servo Sweep example ?

I ran your original code on my Uno R3, with stable 5V supply on my SG90 servo. Runs fine.

I think you do not have the updated servo library that works with the R4
What version of the IDE are you using?

Your photos show the servo connected to a different pin than pin 9 in your code. Looks like yours is connected to D4

You need to install the latest servo library which is 1.2.2
In Library Manager, enter Servo
Select Servo (builtin by Nargolis)
Select 1.2.2

Some of the older versions will not work on the R4

Hi again. Thanks to all of your so incredibly fast and helpful. What an insane community. So the arduino thankfully still puts out 5v. Have learned a lot through this. The port was correct btw. Indeed, it was the library, and so i guess the code got compiled wrong for the r4. Installed the 1.2.2 servo library and now the movement is smooth and continuous as expected. Again: thank you!