any code for arduino to stop servomotor ?

Hi, i'm new in using Servomotor and Arduino. I'm wondering is there any code to stop the servo as once it turn to the a certain angle , it stop completely. For example once the servo turns to 90 degree , instead of delay and turn back to the actually position i want it to stop completely for good.

thank you , any help me be extremely appreciate .

Use a flag.

boolean motorAt90 = 0; // false
...
void loop(){
 if(motorAt90 ==0){
    move motor to 90Degs;
    motorAt90 = 1;  //true
  }
}

For example once the servo turns to 90 degree , instead of delay and turn back to the actually position i want it to stop completely for good.

It is your program that is causing the servo to move from its 90 degree position, so remove the code that does it or prevent it running as has been suggested.

If you posted your code it would be easier to provide help.

anyway heres my code :

#include <Servo.h>

Servo myservo;

void setup()
{
myservo.attach (9);
}

void loop()
{
myservo.writeMicroseconds (1000);
delay (2000);

myservo.writeMicroseconds (2000);
delay (2000);
}

btw the amount microseconds i got is through try and error method to get rotation to 90 degree. i didn’t know that i can directly program the servomotor to move to certain angle (e.g.: 90degree) straightaway

thank you
dan

i didn't know that i can directly program the servomotor to move to certain angle (e.g.: 90degree) straightaway

Why not? It wouldn't take 5 minutes to learn.

You keep telling the servo to move, and then seem surprised that it does just that. I must be missing something.

i try testing using this code :

#include <Servo.h>
Servo servoMain; // Define our Servo

void setup()
{
servoMain.attach(10); // servo on digital pin 10
}

void loop()
{
servoMain.write(45); // Turn Servo Left to 45 degrees
delay(1000); // Wait 1 second
servoMain.write(0); // Turn Servo Left to 0 degrees
delay(1000); // Wait 1 second
servoMain.write(90); // Turn Servo back to center position (90 degrees)
delay(1000); // Wait 1 second
servoMain.write(135); // Turn Servo Right to 135 degrees
delay(1000); // Wait 1 second
servoMain.write(180); // Turn Servo Right to 180 degrees
delay(1000); // Wait 1 second
servoMain.write(90); // Turn Servo back to center position (90 degrees)
delay(1000); // Wait 1 second
}

i found that my servo motor only turn to the left , any chance you guys know whats the reason ?

thanks

Enough tap dancing. You need to tell us about this mysterious servo that you have. It sounds like it isn't really a servo at all. If it has been modified for continuous rotation, as I'm guessing from your questions, then it isn't a servo.

The code works for me using a real servo, but I am not surprised.
Like Paul I suspect that what you have is not a servo at all. Can you give a link to it ?

sorry my bad, what i mean was it turn to the right 45 degree then another right to 90 degree and then turn left back to 45 degree position then back to currently 0 degree position.

i thought it suppose to start from 0 then turn 45 then 90 then 135 then 180 then back to 0 , no ?

and its a servo motor , its a Hitec HS-5245MG servo motor

i thought it suppose to start from 0 then turn 45 then 90 then 135 then 180 then back to 0 , no ?

It would if that was the order of the statements. It isn't:

   servoMain.write(45);  // Turn Servo Left to 45 degrees
   servoMain.write(0);   // Turn Servo Left to 0 degrees
   servoMain.write(90);  // Turn Servo back to center position (90 degrees)
   servoMain.write(135); // Turn Servo Right to 135 degrees
   servoMain.write(180); // Turn Servo Right to 180 degrees
   servoMain.write(90);  // Turn Servo back to center position (90 degrees)

If you want 0, 45, 90, 135, 180, 0, use those values in the write statements, in that order.

i did program to start 0, 45, 90, 135, 180, 0 but how my servo seem to turn start from 0 to 45 to 90 and then hold for 4 seconds then go back to the original position . it never seems to turn to more than 90 degree. i try delete everything and just program it to turn turn 135 or 180 , my servo motor didn't move at all thou.

Write a sketch that tries to move the servo from -90 to 90. Perhaps the point you think is 0 really isn't. Or, perhaps your servo isn't a 180 degree servo. Vague terms about the servo are nowhere near as useful as a link.

i did negative sign , there no help too. But when i write this code
#include <Servo.h>
Servo servoMain; // Define our Servo

void setup()
{
servoMain.attach(10); // servo on digital pin 10
}

void loop()
{
servoMain.writeMicroseconds(750);
delay (1000);
servoMain.writeMicroseconds (2240);
delay (1000);

}

the servo turn 180 degree and then back to original pos. But somehow if i write a code where servo to turn more then 90 degree theres no response .

even when i write
"servoMain.write (0) "or “servoMain.write(135)” or “servoMain.write(180)” individually by itself
theres no response to the servo, the servo just stay still.

only if i write servoMain.write (45 or 90) then only the servo start running.
negative 45 , 90, 135, 180 ,0 all of them no response to the servo.

And yet there is still no link to the servo you have.

How are you powering the servo ? The Arduino digital pins cannot supply enough current for standard size servos.

ermm.... what u mean by link ? heres the model of my servo motor btw: http://www.servoshop.co.uk/index.php?pid=HITHS5245D

i just don't get it why when i write a code of rotation by microseconds the servo allows to turn more than 90 degree but when i write a code of rotation by angle theres no response after more than 90 degree.

Try the sweep example from the servo library. Does that work ?

PaulS:
And yet there is still no link to the servo you have.

He said he’s using one of these:
http://www.servodatabase.com/servo/hitec/hs-5245mg

Henry_Best:

PaulS: And yet there is still no link to the servo you have.

He said he's using one of these: http://www.servodatabase.com/servo/hitec/hs-5245mg

In his next reply. Pay some f**king attention!