Servo Motor Behaving Strangely on Micro

Hi there,

I am using the following code on my arduino micro to control a servo:

#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 
  } 
}

Jup it's from the sweep tutorial..

So the thing is when I connect the servo data cable to the arduino it immediately turns counterclockwise forcing itself against it's mechanical stop. I'm using a sanwa srm102. It came with sanwa dash saber remote/receiver kit. I am using an external power source and I am not trying to run it trough the arduino itself.....

I later then stripped the code to this

#include <Servo.h> 
 
Servo myservo; 

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

and still the same problem, so it seems by just attaching the servo it already malfunctions .

I am probably doing something wrong, any help would be appreciated! :slight_smile:

Hoi reniergoosen, en welkom.

Did you connect the GND of the servo to that of the Arduino ?
GND of the servo is the brown or black wire, and goes to the external supply.
So the GNDs of the Adruino and its supply should be connected to the GND of the servo and its supply.

Thanks for the welcome!

Ahhhh Thanks man that works great!! I cant believe I connected it like that :o

Stupid of me, wasted way to much time on this :frowning:

Thanks for the help!

(apologies for noob question)