Problem with servo motor

i’m having problem with servo motors. When i connect servo motor it just turning for about 30 degress in right direction, when
came to the end it just turn off arduino, when i turn back servo with my hand it’s turn on and do the same.
i use this code

// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott <>

#include <Servo.h>
Servo myservo;  // create servo object to control a servo
int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin
void setup()
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
void loop()
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180)
  myservo.write(val);                  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there

i find it here
i test 3 servo motors and all work the same and i upload different code, but is still the same.

Sorry for my bad english, i’m from Slovenia.

I can't be sure from the video, but it looks like you are running the servo motor from the same 5V supply as the Arduino - if so you must change this, motors and digital electronics should not be sharing a power supply. Basically a motor draws large current spikes on turn on that overwhelm the regulator chip and reset the Arduino. They can also generate damaging voltage spikes - best always to run from a separate supply to delicate electronics.