how to use a servo for a limited amount of time?

Hello there;

I really don’t know this. I am using a continuous servo and I’m trying to find a way to make it spin for a limited amount of time.

Any comments are welcome!

Look at the BlinkWithoutDelay example in the IDE and substitute the servo for the LED

I'm not sure about it. To be specific, I'm trying to get the continuous servo to spin 540 degrees and back, depending on the state of a flex sensor controlling it. So really the Servo is just spinning without stopping.

To be specific, I'm trying to get the continuous servo to spin 540 degrees and back, depending on the state of a flex sensor controlling it.

You cannot control how many degrees a continuous rotation "servo" moves unless it provides some feedback of its position to turn it into a proper servo. The best you can do is to run it for a period of time and hope that it has reached the desired angle and that the load on its output and the supply voltage changes have not affected how fast it moved.

Your stated aim was "to use a servo for a limited time" for which the BWoD principle is perfectly suited.

D_35:
I'm not sure about it. To be specific, I'm trying to get the continuous servo to spin 540 degrees and back, depending on the state of a flex sensor controlling it. So really the Servo is just spinning without stopping.

if you want some help, you need to share a bit more information. you question is very broad and vague.

If you have some already come up with kind of code it would be good if you posted that....

sherzaad:
if you want some help, you need to share a bit more information. you question is very broad and vague.

If you have some already come up with kind of code it would be good if you posted that…

Ok, here’s the code:

 #include <Servo.h>

Servo servo_1;
Servo servo_2;
Servo servo_3;
Servo servo_4;
Servo servo_5;

int flex_1 = 0;//green
int flex_2 = 1;//white
int flex_3 = 2;//yellow
int flex_4 = 3;//orange
int flex_5 = 4;//blue

void setup() {
  servo_1.attach(3);//green
  servo_2.attach(5);//white
  servo_3.attach(6);//yellow
  servo_4.attach(9);//orange
  servo_5.attach(10);//blue
}


void loop() 
{
  int flex_1_pos;
  int servo_1_pos;
  flex_1_pos = analogRead(flex_1);
  servo_1_pos = map(flex_1_pos, 1020, 1023, 0, 180);
  servo_1_pos = constrain(servo_1_pos, 0, 540);
  servo_1.write(servo_1_pos);

  int flex_2_pos;
  int servo_2_pos;
  flex_2_pos = analogRead(flex_2);
  servo_2_pos = map(flex_2_pos, 1020, 1023, 0, 180);
  servo_2_pos = constrain(servo_2_pos, 0, 540);
  servo_2.write(servo_2_pos);

  int flex_3_pos;
  int servo_3_pos;
  flex_3_pos = analogRead(flex_3);
  servo_3_pos = map(flex_3_pos, 1020, 1023, 0, 180);
  servo_3_pos = constrain(servo_3_pos, 0, 540);
  servo_3.write(servo_3_pos);

  int flex_4_pos;
  int servo_4_pos;
  flex_4_pos = analogRead(flex_4);
  servo_4_pos = map(flex_4_pos, 1020, 1023, 0, 180);
  servo_4_pos = constrain(servo_4_pos, 0, 540);
  servo_4.write(servo_4_pos);

  int flex_5_pos;
  int servo_5_pos;
  flex_5_pos = analogRead(flex_5);
  servo_5_pos = map(flex_5_pos, 1022, 1023, 0, 180);
  servo_5_pos = constrain(servo_5_pos, 0, 720);
  servo_5.write(servo_5_pos);
}

//special thanks to Mert Arduino and Huemone Labs

So, it turns out that you have multiple servos, not just one

  int flex_1_pos;
  int servo_1_pos;
  flex_1_pos = analogRead(flex_1);
  servo_1_pos = map(flex_1_pos, 1020, 1023, 0, 180);  
  servo_1_pos = constrain(servo_1_pos, 0, 540);
  servo_1.write(servo_1_pos);

Can you please add comments to each of the lines of code above explaining what each of them does or what you want it to do ?

So it's technically performing a 'hand-like' structure, more here:

flex_1 is a flex sensor; so the position is being read ( I guess )
servo_1 is going from 0 to 540 degrees, but since now I'm using continuous servos, that's different
(I tried modding MG90 micro servos)

Did you follow the advice in reply #1?

(I tried modding MG90 micro servos)

as far as i understood the mod for those things, you remove the gear lock (of the top of my head it is some pin you remove) and you replace the feedback from the variable resistor with 2 fixed-value resistors. You could see if you can tap into the variable resistor (as far as i remeber it is still in there and still operational) and read the output voltage through an analog input.
I am actually busy doing something similar (though bigger size) why do you need a continuous servo ?
And i do hope you take the trouble of actually building a proper shield to attach to the Arduino, those lose cables may work but are highly fragile.
How many servo's are you using keep in mind they can draw up to 650mA each.

I'm using continuous servos because modding MG90s made me fail. I also tried to use BlinkWithoutDelay; I just don't understand.

Ok. I think I figured it out now. Thanks for yyour help.

D_35:
Ok. I think I figured it out now. Thanks for yyour help.

Please post details of your solution
Was it a hardware or software problem or maybe both ?