connecting servo to motor shield

Hi everyone recently got adafruit motor shield v1.0 and was wondering how i go about connecting the servo as nothing seems to be wroking? I also want to connect 2 dc motors as well as the servo simultaneously. I have already tested the motors with this shield and everything works fine its just the servo, could be my code I'm not sure and cant find anything of much use on the internet. I have attached my code and an image of the board and servo.

thanks

#include <Servo.h>
#include <AFMotor.h>


AF_DCMotor Motor1(1);
AF_DCMotor Motor2(3);
Servo myservo;

int pos = 0;


void setup()
{
  myservo.attach(9);
}

void loop()
{
  for(pos = 0; pos <180; pos += 1)
  {
    myservo.write(pos);
    delay(15);
  }
  for(pos = 180; pos>=1; pos-=1)
  {
    myservo.write(pos);
    delay(15);
  }
  
    Motor1.setSpeed(255);
    Motor2.setSpeed(255);
    Motor1.run(FORWARD);
    Motor2.run(FORWARD);
    delay(1000);
    Motor1.run(BACKWARD);
    Motor2.run(BACKWARD);
    delay(1000);
    Motor1.run(FORWARD);
    Motor2.run(BACKWARD);
    delay(1000);
    Motor1.run(BACKWARD);
    Motor2.run(FORWARD);
    delay(1000);
    Motor1.setSpeed(0);
    Motor2.setSpeed(0);
    Motor1.run(BRAKE);
    Motor2.run(BRAKE);
    delay(1000);
}

Thanks for the whole sketch and the photo.
Everything seems fine. But I think that pin 9 uses the lower servo pins and you have the servo connector in the upper servo pins.

Hacker594:
Hi everyone recently got adafruit motor shield v1.0 and was wondering how i go about connecting the servo as nothing seems to be wroking?

You appear to be trying to run your servo from the Arduino power supply. You haven't stated what type of servo you're using, but usually a servo requires more current than the Arduino can supply. I suggest you use an external supply for both your motors and the servo.
N.B. The Adafruit motor shield V1 has the servo numbers reversed on the silkscreen.

Both wrong this is just the standard problem with motor shields and servo. the PWM for the speed control on the motor uses the same timer as servo.h uses to control the servo and this screws things up. Rule of thumb - you can not use servo with a motor shield. Try newservo - look in the playground.

Mark.

holmes4:
Both wrong this is just the standard problem with motor shields and servo. the PWM for the speed control on the motor uses the same timer as servo.h uses to control the servo and this screws things up. Rule of thumb - you can not use servo with a motor shield. Try newservo - look in the playground.

Mark.

Check the Adafruit website. They claim their motor shield works with both at the same time.