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.
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 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.
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.
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!