How to control servo 360

Hello, I am writing the code to control a robot. It has 2 servo 360.
I cannot make it run left and right in fact the servo is running without stopping. How can I limit the time of action of the servo?

It is important because I want that the robot turns right when, through an Android App, I click on the button "Turn Right"

How can I limit the time of action of the servo?

Use batteries. The motor will stop when the battery is dead.

If you had read the stickies at the top of the forum, you would KNOW that you were supposed to post your code.

Posting some information about how the servos are wired would be useful, too.

Please post the code that you are using and a circuit diagram

I take it that you are using a continuous rotation "servo"

To stop such a "servo" you need to write a value of about 90 to it but the exact value will depend on the "servo". If you use writeMicroseconds and use a value of about 1500 you may get better results as it gives finer control.

Use batteries. The motor will stop when the battery is dead.

:art:

The circuit is visible here: http://diymakers.es/wall-e/
I use 2 continuous rotation "servo". The code to go ahead (Avanti) and go back (Indietro) is this:

void Avanti() {
  int DistanzaTesta=0, DistanzaCorpo=0;
  do {
    DistanzaTesta = average_value (100, Sensore_Testa);
    DistanzaCorpo = average_value (100, Sensore_Corpo);
    RuotaDestra.write(0);
    RuotaSinistra.write(180);
  } while (DistanzaTesta > DistanzaLimite && DistanzaCorpo > DistanzaLimite);
  Stop();
}

void Indietro() {
  RuotaDestra.write(180);
  RuotaSinistra.write(0);
}

void Stop() {
  RuotaDestra.write(90);
  RuotaSinistra.write(90);
}

You need to give the people at http://snippets-r-us.com a chance to see your snippets. Here, we expect to see ALL of your code.

Sorry, but my question is clear. I ask how I can control the servo to turn left/right or, better, how I can limit the time of action of my servo.

how I can limit the time of action of my servo.

Record the time.
Start the move.
When sufficient time has elapsed, stop the move.

I ask how I can control the servo to turn left/right

I can not picture the relationship between a servo that rotates at varying speeds and turning left or right.

How?? I wrote this code but it doesn't function

unsigned long previousMillis = 0; // last time update
long interval = 5000; // interval at which to do something (milliseconds)

void Destra() {
  unsigned long currentMillis = millis();
  if(currentMillis - previousMillis > interval) {0
  
     previousMillis = currentMillis;    
    RuotaSinistra.write(180);
  }
}

Pauls: Because I think that it is the only way to turn left/right the robot. Do you know other way? If yes, could you tell me? Thanks

but it doesn't function

It doesn't even compile, so it is nonsense talking about it functioning.

You don't seem to understand the concept of needing to start the motor and at some time later, stop it.

Because I think that it is the only way to turn left/right the robot.

For all I know, you are using the servos for steering. I can't imagine how an electric motor would work for steering. If you are using them for some other purpose, describe that purpose.

If they are, for instance, the drive wheels, it is typically to run TWO at the same time.

They are the drive wheels but, to turn left, I move only one motor.

You don't seem to understand the concept of needing to start the motor and at some time later, stop it

I'm trying to do this, but it never works. When I have to stop the servo? I tried after the condition, but in this case the servo does not start its own.

I'm trying to do this, but it never works. When I have to stop the servo? I tried after the condition, but in this case the servo does not start its own.

Forget about millis() for now. Turn the motor on. delay() for 10 seconds. Turn the motor off. EXACTLY what happens?

It never stops. Move RuotaSinistra continuously

#include <Servo.h>

Servo RuotaSinistra;

void setup() {
  Serial.begin(9600);
  RuotaSinistra.attach(11); 
}

void loop() {
  Destra();
  delay(10000);
  Stop();
}

void Destra() {    
    RuotaSinistra.write(180);
}

void Stop() {
  RuotaSinistra.write(90);
}
void loop() {
  Destra();
  delay(10000);
  Stop();
}

How long do you expect it to stay stopped ?
The loop() function will repeatedly make your code go straight from Stop() to Destra()

So how do I solve? Inserting a switch in the loop? Can you help me with the code? Thanks

Try

void loop() 
{
  Destra();
  delay(10000);
  Stop();
  delay(5000);
}

and experiment from there

So how do I solve?

Engage your brain. I mentioned that there were 4 things that needed to happen to blink an LED, and that your code did only 3 of them. It isn't rocket science to determine what the 4 are, or which your code is missing.