360° Servo always returns to a certain position

Hello,
I am trying to control a 360° servo, so it runs in one direction for a given time and then stops exactly there. This is my code for now:

#include <Servo.h>  
Servo Servo1;

void setup() {
    Servo1.attach(39);
}

void loop() {
  ServoMove(2500);
  delay(5000);
  ServoMove(5000);
  delay(5000);
}

void ServoMove(int TimeToMove){
  Servo1.write(180);
  delay(TimeToMove);
  Servo1.write(90);
}

The problem is: When it comes to break time, it turns to a certain position one last time. This position is always the same.
Does anyone know what I'm doing wrong or how I can get it to stop and stay there ?

Welcome to the forum
Thanks for using code tags in your first post as many newcomers don't

What exactly do you mean by this ?

Please describe exactly what you want the servo to do

Are you expecting to be able to position the servo exactly ? If it is a continuous rotation "servo" then you cannot control its position, only its speed and direction.

Writing a value of approximately 90 to it will stop it but you will need to experiment with the value and it may change as the supply voltage changes

Hi

I mean the delay of 5000 millis in the loop.

No, not directly. But if I spin the servo for a certain period of time and then stop it, it should stop at a certain position. So if I rotate it in oposite direction for the exact period of time it would be in the same position where it started, right ?

I tried but it didn't work. The problem is not that the Servo does not stop rotating, he does, But before that, he rotates back to 0 position (I don´t know if it´s called 0 but I think so because it´s always the same spot).

I hope you understand my Problem.
Thanks for now :smiley:

It's not actually clear if your servo is a

  1. 360 continuous servo that spins round and round like a dc motor, or
  2. a servo that goes 0-360 one way and can't go further, then goes 360-0 back the other way to an end stop

Oh sorry I forgot to mention that, its a 360° continous servo.
It will spin in one direction until the ".write(90)" line, than it rotates to the 0 position and stops.

Well a continuous servo has no notion of "position".

Without some kind of feedback, which it lost with a continuous servo, it will be pretty much impossible for the motor to behave so precisely as to stop at the same place when you stop it turning, and then to go exactly the same distance the other way. Stretching the bounds of reality there I'd say.

Okay yes, but there is still the problem that it always rotates to this special angle/position (or what ever). I've seen a lot of videos but none of these do that.
:frowning:

Wrong

In any case you move the servo for different periods, 2500 and 5000

As I said

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