Servo motor control

I'm 13 years old.
I'm new to arduino and I tried to control a servo motor goes 0 to 180 position and come back and stop but I failed to do that . So help me to do this !

Thank you!

Welcome to the Forum.

Have you studied the servo sweep example that comes with the Arduino IDE?

Post the code you are having a problem with.

...R

Are you sure you haven't got a continuous rotation (ex-) servo?
Post your code (use code tags).

I deleted the other copy of this question - DO NOT CROSS-POST, CROSS-POSTING WASTES TIME.

Thank you for your fastest response !

Yes I did , but I didn't use a separate code , but I used the 'sweep' code by modifying it . But every time I didn't got the correct code. So can you send me a new code.

This is the 'sweep' code ,what I've modified ,

// Sweep
// by BARRAGAN http://barraganstudio.com
// This example code is in the public domain.

#include <Servo.h>

Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created

int pos = 0; // variable to store the servo position

void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}

void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}

Thank you!

Have you connected the servo to pin 9?
have you got the servo ground connected to the Arduino's ground?

What is it doing?

(Where are the code tags?)

Yes , I did all the things .But the servo work like this ,
First the servo goes 0 to 180 ,
Then comes back to 0 ,
Again it goes to 180 and come back ,
Again it goes to 180 ,
So like that the servo runs repeatedly ,

( what are you regarding about code tags ?)

Thank you!

If you only want it to run once, put all the code into "setup()" and leave "loop()" empty.

I wrote the code but at the compiling it shows some errors .

Sorry there was a small mistake.it's work properly .

Thank you very much !!!