Code causing motors to malfunction

I have currently written a code which effectively uses 3 out of 4 channels with an R/C remote found here http://www.tetrixrobotics.com/RC_Controllers/Wireless_Joystick_Gamepad_System
to interface with an arduino and Adafruit motorshield. My problem is that as soon as I try to add the 4th channel and make it do something it causes one set of motor to jitter and not run smoothly as if it is constantly receiving and then not receiving power.
here is the code that works

#include <Servo.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"

int ch1; 
int ch2;
int ch3;
int ch4;

Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *driveWheel1 = AFMS.getMotor(1);
Adafruit_DCMotor *driveWheel2 = AFMS.getMotor(2);
Adafruit_DCMotor *armMotor1 = AFMS.getMotor(3);
Adafruit_DCMotor *armMotor2 = AFMS.getMotor(4);

Servo claw;
int servoPin = 9;
int pos = 0;
Servo arm;
int servoPin2 = 10;
int pos2 = 0;

unsigned long previousMillis1 = 0;
unsigned long previousMillis2 = 0;
long onTime1 = 100;
long onTime2 = 100;

void setup() 
{
  AFMS.begin();
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  pinMode(A2, INPUT);
  pinMode(A3, INPUT);
  Serial.begin(9600);
  driveWheel1->setSpeed(180);
  driveWheel2->setSpeed(180);
  armMotor1->setSpeed(255);
  armMotor2->setSpeed(255);
  claw.attach(servoPin);
  arm.attach(servoPin2);
  
 
 
 
}

void loop() 
{
 unsigned long currentMillis = millis();
 ch1 = pulseIn(A0, HIGH, 25000);
 ch2 = pulseIn(A1, HIGH, 25000);
 ch3 = pulseIn(A2, HIGH, 25000);
 ch4 = pulseIn(A3, HIGH, 25000);
 if(ch4 > 1500)
 {
  Serial.println("Right Switch: Engaged");
 driveWheel1->run(FORWARD);
 driveWheel2->run(BACKWARD);
 }
 if(ch4 < 1400)
 {
  Serial.println("Right Switch: Disengaged");
  driveWheel1->run(BACKWARD);
  driveWheel2->run(FORWARD);
 }
 if((ch4 > 1400) && (ch4 < 1500))
 {
  Serial.println("Right Switch: Neutral");
  driveWheel1->run(RELEASE);
  driveWheel2->run(RELEASE);
 }

if(ch3 > 1500)
{
  Serial.println("Left Switch: Forward");
  armMotor1->run(FORWARD);
  armMotor2->run(FORWARD);
   Serial.println("bend forward");
    if(currentMillis - previousMillis2 >= onTime2)
     {
     for(pos2 = 0; pos2 < 170; pos2++)
      {
      arm.write(pos2);
      }
     previousMillis2 = currentMillis;
     }
}
if(ch3 < 1400)
{
  Serial.println("Left Switch: BACKWARD");
  armMotor1->run(BACKWARD);
  armMotor2->run(BACKWARD);
   Serial.println("bend backward");
    if(currentMillis - previousMillis2 >= onTime2)
     {
     for(pos2 = 170; pos2 > 0; pos2--)
      {
      arm.write(pos2);
      }
     }
}
if((ch3 > 1400) && (ch3 < 1500))
  {
  Serial.println("Left Switch: Neutral");
  Serial.println("normal");
  armMotor1->run(RELEASE);
  armMotor2->run(RELEASE);
  }
 if(ch1 > 1500)
 {
  Serial.println("grab");
  if(currentMillis - previousMillis1 >= onTime1)
    {
    
   for(pos = 0; pos < 170; pos++)
     {
      claw.write(pos);
     }
     previousMillis1 = currentMillis;
    }
  
 }
 if(ch1 < 1350)
 {
  Serial.println("Release");
  if(currentMillis - previousMillis1 >= onTime1)
    {
     for(pos = 170; pos > 0; pos--) 
       {
       claw.write(pos);
       }  
      previousMillis1 = currentMillis;
    }
 }
 if((ch1 > 1350) && (ch2 < 1500))
  {
    Serial.println("nothing");
  }

}

and here is the one that causes problems by adding the 4th channel

#include <Servo.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"

int ch1; 
int ch2;
int ch3;
int ch4;

Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *driveWheel1 = AFMS.getMotor(1);
Adafruit_DCMotor *driveWheel2 = AFMS.getMotor(2);
Adafruit_DCMotor *armMotor1 = AFMS.getMotor(3);
Adafruit_DCMotor *armMotor2 = AFMS.getMotor(4);

Servo claw;
int servoPin = 9;
int pos = 0;
Servo arm;
int servoPin2 = 10;
int pos2 = 0;

unsigned long previousMillis1 = 0;
unsigned long previousMillis2 = 0;
long onTime1 = 100;
long onTime2 = 100;

void setup() 
{
  AFMS.begin();
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  pinMode(A2, INPUT);
  pinMode(A3, INPUT);
  Serial.begin(9600);
  driveWheel1->setSpeed(180);
  driveWheel2->setSpeed(180);
  armMotor1->setSpeed(255);
  armMotor2->setSpeed(255);
  claw.attach(servoPin);
  arm.attach(servoPin2);
  
 
 
 
}

void loop() 
{
 unsigned long currentMillis = millis();
 ch1 = pulseIn(A0, HIGH, 25000);
 ch2 = pulseIn(A1, HIGH, 25000);
 ch3 = pulseIn(A2, HIGH, 25000);
 ch4 = pulseIn(A3, HIGH, 25000);
 if(ch4 > 1500)
 {
  Serial.println("Right Switch: Engaged");
 driveWheel1->run(FORWARD);
 driveWheel2->run(BACKWARD);
 }
 if(ch4 < 1400)
 {
  Serial.println("Right Switch: Disengaged");
  driveWheel1->run(BACKWARD);
  driveWheel2->run(FORWARD);
 }
 if((ch4 > 1400) && (ch4 < 1500))
 {
  Serial.println("Right Switch: Neutral");
  driveWheel1->run(RELEASE);
  driveWheel2->run(RELEASE);
 }

if(ch3 > 1500)
{
  Serial.println("Left Switch: Forward");
  armMotor1->run(FORWARD);
  armMotor2->run(FORWARD);
   Serial.println("bend forward");
    if(currentMillis - previousMillis2 >= onTime2)
     {
     for(pos2 = 0; pos2 < 170; pos2++)
      {
      arm.write(pos2);
      }
     previousMillis2 = currentMillis;
     }
}
if(ch3 < 1400)
{
  Serial.println("Left Switch: BACKWARD");
  armMotor1->run(BACKWARD);
  armMotor2->run(BACKWARD);
   Serial.println("bend backward");
    if(currentMillis - previousMillis2 >= onTime2)
     {
     for(pos2 = 170; pos2 > 0; pos2--)
      {
      arm.write(pos2);
      }
     }
}
if((ch3 > 1400) && (ch3 < 1500))
  {
  Serial.println("Left Switch: Neutral");
  Serial.println("normal");
  armMotor1->run(RELEASE);
  armMotor2->run(RELEASE);
  }
 if(ch1 > 1500)
 {
  Serial.println("grab");
  if(currentMillis - previousMillis1 >= onTime1)
    {
    
   for(pos = 0; pos < 170; pos++)
     {
      claw.write(pos);
     }
     previousMillis1 = currentMillis;
    }
  
 }
 if(ch1 < 1350)
 {
  Serial.println("Release");
  if(currentMillis - previousMillis1 >= onTime1)
    {
     for(pos = 170; pos > 0; pos--) 
       {
       claw.write(pos);
       }  
      previousMillis1 = currentMillis;
    }
 }
 if((ch1 > 1350) && (ch2 < 1500))
  {
    Serial.println("nothing");
  }
 if(ch2 > 1500)
  {
    Serial.println("go forward");
    driveWheel1->run(FORWARD);
    driveWheel2->run(FORWARD);

 }
 if(ch2 < 1350)
  {
    Serial.println("go backward");
    driveWheel1->run(BACKWARD);
    driveWheel2->run(BACKWARD);

 }
 if((ch2 > 1350) && (ch1 < 1500))
 {
  Serial.println("stay still");
  driveWheel1->run(RELEASE);
  driveWheel2->run(RELEASE);
 }
}

Power or wiring problem? Schematic (photo/scan of hand-drawn one if needed) and links to the components that you have used will help. Of special interest will be how everything is powered; if e.g. everything is driven from the 5V of the Arduino, the USB or on-board voltage regulator might not be able to deliver sufficient power to drive all motors).

What happens if you disconnect other motors?

Here are the components which I can find a link for
remote - http://www.tetrixrobotics.com/RC_Controllers/Wireless_Joystick_Gamepad_System
receiver - http://www.tetrixrobotics.com/RC_Receiver
motorshield - Overview | Adafruit Motor Shield V2 | Adafruit Learning System
4 spare DC motors from low quality rc cars
Arduino uno
The motorshield is powered by an external battery while the servo is powered by the regulated 5v. What is especially strange to me is that the first code in my first post uses all 4 of the attached motors and servo fine so it doesn't seem to be a problem with how it is wired or powered. It is only when I try to make the 4th channel control the same two motors as another channel but move them in different directions that the problem occurs as seen in the second code.

Please do not cross-post. Other thread removed.

Huntechr1:
What is especially strange to me is that the first code in my first post uses all 4 of the attached motors and servo fine so it doesn't seem to be a problem with how it is wired or powered.

Ah, missed that.

Huntechr1:
It is only when I try to make the 4th channel control the same two motors as another channel but move them in different directions that the problem occurs as seen in the second code.

I think that that makes sense (as far as I understand the code). ch2 controls the two driveWheels. ch4 does the same. If ch4 is e.g. 1450, it will release the motors. But if at that same time ch2 is smaller than 1350 (e.g. 1300), the motors will run backward. And next ch4 (1450) will release them again and ch2 (1300) will make it run backward and so on

Note: I don't know much about remotes and channels :wink: