user59631: When myservo_1,myservo_2,myservo_3,myservo_4 is commented, I can't control the speed of my M1 motor. But only when I uncomment myservo_1 and so on, I can control the motor speed again. 
Can someone help me? My codes are listed down below:
#include <Servo.h>
Servo myservo_1;
Servo myservo_2;
Servo myservo_3;
Servo myservo_4;

int SensorL = 0;
int SensorR = 0;
int SensorM = 0;

#define E1 10
#define M1 12
#define E2 11
#define M2 13
int pos = 0;
int incomingByte = 0;

void setup()
{
  Serial.begin(9600);
  myservo_1.attach(9);
  myservo_2.attach(8);
  myservo_3.attach(7);
  myservo_4.attach(6);
  pinMode(SensorL, INPUT);
  pinMode(SensorR, INPUT);
  pinMode(SensorM, INPUT);
  pinMode(M1, OUTPUT);
  pinMode(M2, OUTPUT);
//  pinMode(E1, OUTPUT);
//  pinMode(E2, OUTPUT);
}

void loop()
{
  SensorR = digitalRead(2);
  SensorL = digitalRead(3);
  SensorM = digitalRead(5);

  if (SensorL == LOW && SensorR == LOW && SensorM == HIGH)
  {
    digitalWrite(M1, HIGH);
    digitalWrite(M2, HIGH);
    analogWrite(E1, 255);
    analogWrite(E2, 255);
    Serial.println(" FORWARD ");
    //delay(1);
  }
  if (SensorL == HIGH && SensorR == LOW && SensorM == HIGH)
  {
    digitalWrite(M1, HIGH);
    digitalWrite(M2, LOW);
    analogWrite(E1, 255);
    analogWrite(E2, 255);
    Serial.println(" LEFT ");
    //delay(1);
  }
  if (SensorL == LOW && SensorR == HIGH && SensorM == HIGH) //move right
  {
    digitalWrite(M1, LOW);
    digitalWrite(M2, HIGH);
    analogWrite(E1, 255);
    analogWrite(E2, 255);
    Serial.println(" RIGHT ");
    //delay(1);
  }

  if (SensorL == HIGH && SensorR == HIGH && SensorM == HIGH) //stop
  {
    digitalWrite(M1, HIGH);
    digitalWrite(M2, HIGH);
    analogWrite(E1, 0);
    analogWrite(E2, 0);
    Serial.println(" STOP ");
    //delay(1);
  }

  if (SensorL == HIGH && SensorR == LOW && SensorM == LOW) //move left
  {
    digitalWrite(M1, HIGH);
    digitalWrite(M2, LOW);
    analogWrite(E1, 125);
    analogWrite(E2, 125);
    Serial.println(" LEFT ");
    //delay(1);
  }

  if (SensorL == LOW && SensorR == HIGH && SensorM == LOW) //move right
  {
    digitalWrite(M1, LOW);
    digitalWrite(M2, HIGH);
    analogWrite(E1, 125);
    analogWrite(E2, 125);
    Serial.println(" MoVE Right ");
    //delay(1);
  }


  if (Serial.available() > 0)
  {
    incomingByte = Serial.read();
    {
      {
        if (incomingByte == 'J')//ARM OPEN
        {
          myservo_1.write(0);
          Serial.println(" ARM OPEN ");
        }
        if (incomingByte == 'L')//ARM CLOSE
        {
          myservo_1.write(180);
          Serial.println(" ARM CLOSE ");
        }
        if (incomingByte == 'I')//ARM UP
        {
          myservo_2.write(0);
          myservo_3.write(180);
          Serial.println(" ARM UP ");
        }
        if (incomingByte == 'K')//ARM DOWN
        {
          myservo_2.write(180);
          myservo_3.write(0);
          Serial.println(" ARM DOWN ");
        }
        if (incomingByte == 'U')//ROTATE LEFT
        {
          myservo_4.write(0);
          Serial.println(" ROTATE LEFT ");
        }
        if (incomingByte == 'O')//ROTATE RIGHT
        {
          myservo_4.write(180);
          Serial.println(" ROATE RIGHT ");
        }
        if (incomingByte == 'M')
        {
          myservo_1.write(90);
          myservo_2.write(90);
          myservo_3.write(90);
          myservo_4.write(90);
          Serial.println(" ALL STOP ");
        }
        if (incomingByte == 'N')//ARM STOP
        {
          myservo_1.write(90);
          Serial.println(" ARM STOP ");
        }
        if (incomingByte == 'B')//UP DOWN STOP
        {
          myservo_2.write(90);
          myservo_3.write(90);
          Serial.println(" UP DOWN STOP ");
        }
        if (incomingByte == 'V')//ROTATION STOP
        {
          myservo_4.write(90);
          Serial.println(" ROTATION STOP ");
        }
        if (incomingByte == 'W')
        {
          digitalWrite(M1, HIGH);
          digitalWrite(M2, HIGH);
          analogWrite(E1, 200);
          analogWrite(E2, 0);
          Serial.println(" FORWARD ");
        }
        if (incomingByte == 'Z')
        {
          digitalWrite(M1, HIGH);
          digitalWrite(M2, HIGH);
          analogWrite(E1, 255);
          analogWrite(E2, 255);
          Serial.println(" FORWARD ");
          delay(100);
        }
        if (incomingByte == 'S')
        {
          digitalWrite(M1, LOW);
          digitalWrite(M2, LOW);
          analogWrite(E1, 255);
          analogWrite(E2, 255);
          Serial.println(" REVERSE ");
        }
        if (incomingByte == 'A')
        {
          digitalWrite(M1, HIGH);
          digitalWrite(M2, LOW);
          analogWrite(E1, 255);
          analogWrite(E2, 255);
          Serial.println(" LEFT ");
        }
        if (incomingByte == 'D')
        {
          digitalWrite(M1, LOW);
          digitalWrite(M2, HIGH);
          analogWrite(E1, 255);
          analogWrite(E2, 255);
          Serial.println(" TURNING RIGHT ");
        }
        if (incomingByte == 'X')
        {
          digitalWrite(M1, LOW);
          digitalWrite(M2, HIGH);
          analogWrite(E1, 0);
          analogWrite(E2, 0);
          Serial.println(" STOP MANAUAL ");
        }
        if (incomingByte == 'w')
        {
          digitalWrite(M1, HIGH);
          digitalWrite(M2, HIGH);
          analogWrite(E1, 125);
          analogWrite(E2, 125);
          Serial.println(" SLOW FORWARD ");
        }
        if (incomingByte == 's')
        {
          digitalWrite(M1, LOW);
          digitalWrite(M2, LOW);
          analogWrite(E1, 125);
          analogWrite(E2, 125);
          Serial.println(" SLOW REVERSE ");
        }
        if (incomingByte == 'a')
        {
          digitalWrite(M1, HIGH);
          digitalWrite(M2, LOW);
          analogWrite(E1, 125);
          analogWrite(E2, 125);
          Serial.println(" SLOW LEFT ");
        }
        if (incomingByte == 'd')
        {
          digitalWrite(M1, LOW);
          digitalWrite(M2, HIGH);
          analogWrite(E1, 125);
          analogWrite(E2, 125);
          Serial.println(" SLOW RIGHT ");
        }
      }
    }
  }
}


user2881: The Servo library uses timer 1 to send the signals to the servos. But timer 1 is also used to run PWM on pins 9 and 10. It can't however do both. 
So since Motor E1 uses pin 10, and timer 1 is already used by the Servo library, PWM, and by extension, analogWrite doesn't work.
E2 uses pin 11, which uses timer 2 for it's PWM, so is therefor no affected. 
So move E1 to one of the PWM pins, other than 9 and 10, and thing should start working again.
I however don't know why M1 doesn't work.

59631: <p>When <code>myservo_1,myservo_2,myservo_3,myservo_4</code> is commented, I can't control the speed of my M1 motor. But only when I uncomment <code>myservo_1</code> and so on, I can control the motor speed again. </p>

<p>Can someone help me? My codes are listed down below:</p>

<pre><code>#include &lt;Servo.h&gt;
Servo myservo_1;
Servo myservo_2;
Servo myservo_3;
Servo myservo_4;

int SensorL = 0;
int SensorR = 0;
int SensorM = 0;

#define E1 10
#define M1 12
#define E2 11
#define M2 13
int pos = 0;
int incomingByte = 0;

void setup()
{
  Serial.begin(9600);
  myservo_1.attach(9);
  myservo_2.attach(8);
  myservo_3.attach(7);
  myservo_4.attach(6);
  pinMode(SensorL, INPUT);
  pinMode(SensorR, INPUT);
  pinMode(SensorM, INPUT);
  pinMode(M1, OUTPUT);
  pinMode(M2, OUTPUT);
//  pinMode(E1, OUTPUT);
//  pinMode(E2, OUTPUT);
}

void loop()
{
  SensorR = digitalRead(2);
  SensorL = digitalRead(3);
  SensorM = digitalRead(5);

  if (SensorL == LOW &amp;&amp; SensorR == LOW &amp;&amp; SensorM == HIGH)
  {
    digitalWrite(M1, HIGH);
    digitalWrite(M2, HIGH);
    analogWrite(E1, 255);
    analogWrite(E2, 255);
    Serial.println(" FORWARD ");
    //delay(1);
  }
  if (SensorL == HIGH &amp;&amp; SensorR == LOW &amp;&amp; SensorM == HIGH)
  {
    digitalWrite(M1, HIGH);
    digitalWrite(M2, LOW);
    analogWrite(E1, 255);
    analogWrite(E2, 255);
    Serial.println(" LEFT ");
    //delay(1);
  }
  if (SensorL == LOW &amp;&amp; SensorR == HIGH &amp;&amp; SensorM == HIGH) //move right
  {
    digitalWrite(M1, LOW);
    digitalWrite(M2, HIGH);
    analogWrite(E1, 255);
    analogWrite(E2, 255);
    Serial.println(" RIGHT ");
    //delay(1);
  }

  if (SensorL == HIGH &amp;&amp; SensorR == HIGH &amp;&amp; SensorM == HIGH) //stop
  {
    digitalWrite(M1, HIGH);
    digitalWrite(M2, HIGH);
    analogWrite(E1, 0);
    analogWrite(E2, 0);
    Serial.println(" STOP ");
    //delay(1);
  }

  if (SensorL == HIGH &amp;&amp; SensorR == LOW &amp;&amp; SensorM == LOW) //move left
  {
    digitalWrite(M1, HIGH);
    digitalWrite(M2, LOW);
    analogWrite(E1, 125);
    analogWrite(E2, 125);
    Serial.println(" LEFT ");
    //delay(1);
  }

  if (SensorL == LOW &amp;&amp; SensorR == HIGH &amp;&amp; SensorM == LOW) //move right
  {
    digitalWrite(M1, LOW);
    digitalWrite(M2, HIGH);
    analogWrite(E1, 125);
    analogWrite(E2, 125);
    Serial.println(" MoVE Right ");
    //delay(1);
  }


  if (Serial.available() &gt; 0)
  {
    incomingByte = Serial.read();
    {
      {
        if (incomingByte == 'J')//ARM OPEN
        {
          myservo_1.write(0);
          Serial.println(" ARM OPEN ");
        }
        if (incomingByte == 'L')//ARM CLOSE
        {
          myservo_1.write(180);
          Serial.println(" ARM CLOSE ");
        }
        if (incomingByte == 'I')//ARM UP
        {
          myservo_2.write(0);
          myservo_3.write(180);
          Serial.println(" ARM UP ");
        }
        if (incomingByte == 'K')//ARM DOWN
        {
          myservo_2.write(180);
          myservo_3.write(0);
          Serial.println(" ARM DOWN ");
        }
        if (incomingByte == 'U')//ROTATE LEFT
        {
          myservo_4.write(0);
          Serial.println(" ROTATE LEFT ");
        }
        if (incomingByte == 'O')//ROTATE RIGHT
        {
          myservo_4.write(180);
          Serial.println(" ROATE RIGHT ");
        }
        if (incomingByte == 'M')
        {
          myservo_1.write(90);
          myservo_2.write(90);
          myservo_3.write(90);
          myservo_4.write(90);
          Serial.println(" ALL STOP ");
        }
        if (incomingByte == 'N')//ARM STOP
        {
          myservo_1.write(90);
          Serial.println(" ARM STOP ");
        }
        if (incomingByte == 'B')//UP DOWN STOP
        {
          myservo_2.write(90);
          myservo_3.write(90);
          Serial.println(" UP DOWN STOP ");
        }
        if (incomingByte == 'V')//ROTATION STOP
        {
          myservo_4.write(90);
          Serial.println(" ROTATION STOP ");
        }
        if (incomingByte == 'W')
        {
          digitalWrite(M1, HIGH);
          digitalWrite(M2, HIGH);
          analogWrite(E1, 200);
          analogWrite(E2, 0);
          Serial.println(" FORWARD ");
        }
        if (incomingByte == 'Z')
        {
          digitalWrite(M1, HIGH);
          digitalWrite(M2, HIGH);
          analogWrite(E1, 255);
          analogWrite(E2, 255);
          Serial.println(" FORWARD ");
          delay(100);
        }
        if (incomingByte == 'S')
        {
          digitalWrite(M1, LOW);
          digitalWrite(M2, LOW);
          analogWrite(E1, 255);
          analogWrite(E2, 255);
          Serial.println(" REVERSE ");
        }
        if (incomingByte == 'A')
        {
          digitalWrite(M1, HIGH);
          digitalWrite(M2, LOW);
          analogWrite(E1, 255);
          analogWrite(E2, 255);
          Serial.println(" LEFT ");
        }
        if (incomingByte == 'D')
        {
          digitalWrite(M1, LOW);
          digitalWrite(M2, HIGH);
          analogWrite(E1, 255);
          analogWrite(E2, 255);
          Serial.println(" TURNING RIGHT ");
        }
        if (incomingByte == 'X')
        {
          digitalWrite(M1, LOW);
          digitalWrite(M2, HIGH);
          analogWrite(E1, 0);
          analogWrite(E2, 0);
          Serial.println(" STOP MANAUAL ");
        }
        if (incomingByte == 'w')
        {
          digitalWrite(M1, HIGH);
          digitalWrite(M2, HIGH);
          analogWrite(E1, 125);
          analogWrite(E2, 125);
          Serial.println(" SLOW FORWARD ");
        }
        if (incomingByte == 's')
        {
          digitalWrite(M1, LOW);
          digitalWrite(M2, LOW);
          analogWrite(E1, 125);
          analogWrite(E2, 125);
          Serial.println(" SLOW REVERSE ");
        }
        if (incomingByte == 'a')
        {
          digitalWrite(M1, HIGH);
          digitalWrite(M2, LOW);
          analogWrite(E1, 125);
          analogWrite(E2, 125);
          Serial.println(" SLOW LEFT ");
        }
        if (incomingByte == 'd')
        {
          digitalWrite(M1, LOW);
          digitalWrite(M2, HIGH);
          analogWrite(E1, 125);
          analogWrite(E2, 125);
          Serial.println(" SLOW RIGHT ");
        }
      }
    }
  }
}
</code></pre>
 2881: <p>The Servo library uses <code>timer 1</code> to send the signals to the servos. But <code>timer 1</code> is also used to run PWM on pins 9 and 10. It can't however do both. </p>

<p>So since Motor E1 uses pin 10, and <code>timer 1</code> is already used by the Servo library, PWM, and by extension, <code>analogWrite</code> doesn't work.</p>

<p>E2 uses pin 11, which uses <code>timer 2</code> for it's PWM, so is therefor no affected. </p>

<p>So move E1 to one of the PWM pins, other than 9 and 10, and thing should start working again.</p>

<p>I however don't know why M1 doesn't work.</p>
