Servo control issues

Hi,
I am new to Servo control, and having some issues to let the Servo make a sweep form 0 to 180 and back.
Should be easy, but can not get it to work.
When I connect the power to the servo it will center, but when I connect the yellow control wire, the servo will rotate all the way to one side, every time, all the way to the end, and will not move any more. Every change in the program wont make any difference.

I hope someone can help me out.

Thanks in advance Arjen from the Netherlands.

Setup:
Pololu A-star 328 PB 5V 16Mhz
separate power source 7,4 Volt

Tower Pro MG90S Micro servo
Separate Power Source 4,6 Volt.
(works fine on servo tester)

Program:

#include <Servo.h>

Servo myservo; // create servo object to control a servo

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

void loop()
{
myservo.write(10); // sets the servo position according to the scaled value
delay(1000); // waits for the servo to get there
myservo.write(170); // sets the servo position according to the scaled value
delay(1000); // waits for the servo to get there
}

(deleted)

spycatcher2k:
Have you remembered to connect a common ground?

The board and servo are not using the same power supply and therefor not the same ground. Is that needed?
When I connect to the same power supply, it seems that the servo is not working due to the higher voltage.

Yes the negative of the servo power supply must be connected to the Arduino GND. If you don't do that the signal to the servo has no reference.

slipstick:
Yes the negative of the servo power supply must be connected to the Arduino GND. If you don't do that the signal to the servo has no reference.

Huge Thanks, this solved my problem !!

Thanks

spycatcher2k:
Have you remembered to connect a common ground?

Thanks a lot, This was indeed the problem, now it works fine !

@koekwous

Your topic was Moved to it's current location / section as it is more suitable.

Could you also take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.