Motor Shield V1.0 Problem

Hello I’m using the Motor Shield V1.0 and I’m having problems when connecting servos. I have a DC motor running perfectly. But when I code the servo to the Arduino de DC motor stops working. Below its the code I’m using and its commented which line of code gives me the problem. Please let me know if you know the problem that I’m having. Because I don’t understand why does it stop moving when this line its active. My plan is to connect 4 servos to this shield. But if only one servo its giving me problems I cant continue with my project. I have an Arduino UNO and a MEGA. If the solution its switching form one to another please let me know.

#include <Servo.h>

//Motor-A

int pinI1 = 8;//define I1 interface
int pinI2 = 11;//define I2 interface
int speedpinA = 9;//enable motor A

//Motor-B

int pinI3 = 12;//define I3 interface
int pinI4 = 13;//define I4 interface
int speedpinB = 10;//enable motor B

//Set Speed for motors

int speed = 127;//define the speed of motor

//Set servo
Servo myservo;

void setup()
{

pinMode(pinI1,OUTPUT);
pinMode(pinI2,OUTPUT);
pinMode(speedpinA,OUTPUT);
pinMode(pinI3,OUTPUT);
pinMode(pinI4,OUTPUT);
pinMode(speedpinB,OUTPUT);
//myservo.attach(2); //HERE ITS MY PROBLEM WHEN THIS LINE OF CODE ITS ACTIVE THE DC MOTOR DOESN’T WORK
}

void forward()
{
analogWrite(speedpinA,speed);//input a simulation value to set the speed
analogWrite(speedpinB,speed);
digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
digitalWrite(pinI3,LOW);
digitalWrite(pinI2,LOW);//turn DC Motor A move anticlockwise
digitalWrite(pinI1,HIGH);
}
void backward()//
{
analogWrite(speedpinA,speed);//input a simulation value to set the speed
analogWrite(speedpinB,speed);
digitalWrite(pinI4,LOW);//turn DC Motor B move anticlockwise
digitalWrite(pinI3,HIGH);
digitalWrite(pinI2,HIGH);//turn DC Motor A move clockwise
digitalWrite(pinI1,LOW);
}
void left()//
{
analogWrite(speedpinA,speed);//input a simulation value to set the speed
analogWrite(speedpinB,speed);
digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
digitalWrite(pinI3,LOW);
digitalWrite(pinI2,HIGH);//turn DC Motor A move clockwise
digitalWrite(pinI1,LOW);
}
void right()//
{
analogWrite(speedpinA,speed);//input a simulation value to set the speed
analogWrite(speedpinB,speed);
digitalWrite(pinI4,LOW);//turn DC Motor B move anticlockwise
digitalWrite(pinI3,HIGH);
digitalWrite(pinI2,LOW);//turn DC Motor A move clockwise
digitalWrite(pinI1,HIGH);
}
void stop()//
{
digitalWrite(speedpinA,LOW);// Unenble the pin, to stop the motor. this should be done to avid damaging the motor.
digitalWrite(speedpinB,LOW);
delay(1000);

}

void loop()
{

left();
delay(2000);
stop();
right();
delay(2000);
stop();
// delay(2000);
forward();
delay(2000);
stop();
backward();
delay(2000);
stop();

}

Hello

This problem is because the same PWM pin is used by both the library.
The Servo library also uses pin 9 and 10 for PWM.
So change the following line in the code.

int speedpinA = 5;//enable motor A to D5

int speedpinB = 6;//enable motor B to D6

and let us know if it works

Thanks and regards