Ive done as you said, Erased part of the code to simplify it and have common ground with the arduino. The arduino has its own power supply from a 9v battery. Its still acting strange, when i input my code...
#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
myservo.write(180); //starts servo moving as fast as it can go CCW
delay(400); //waits for the server to move
}
void loop()
{
}
The servo will execute the code once or twice each time the code is uploaded. After this the servo will act strange and sometimes will not even move each time the code is uploaded until i change the power source, then the same happens again. when i upload an example from the arduino library, the servo does as it is meant to with out any issues.
I'm a bit confused why its acting like this.