Code Problems: 12 Servos With Arduino Mega

I don’t expect to get much help, but i’ll post this up and see what happens
I’m trying to control 12 servos for my Lynxmotion Scout, it’s really just some code to test maximum and minimum joint angles
My problem is that the code worked fine on my Arduino Mega 2560 ADK with just six servos, but after modding the code to run 12
not even a single servo will run. I soldered up a basic… servo… holder thing, that routes pins to the correct spots on the board, and I’ve checked the hardware countless
times. Can someone give a read through to my code and give me some help.
Also… source code for a full Lynxmotion scout controlled via serial cable? I’ve looked everywhere, but yet to stumble upon anything.

Pins 2-13 are used for PWM

/** Adjust these values for your servo and setup, if necessary **/  
int servo1     =  2;    // control pin for servo motor
int servo2     =  3;
int minPulse     =  900;  // minimum servo position  
int maxPulse     =  2100; // maximum servo position  
int minPulse2     =  900;  // minimum servo position  
int maxPulse2     =  2100; // maximum servo position  
int turnRate     =  100;  // servo turn rate increment (larger value, faster rate) 
int turnRate2     =  100;
int refreshTime  =  20;   // time (ms) between pulses (50Hz)  
int refreshTime2  =  20;   // time (ms) between pulses (50Hz

int servo3     =  4;    // control pin for servo motor
int servo4     =  5;
int minPulse3     =  900;  // minimum servo position  
int maxPulse3     =  2100; // maximum servo position  
int minPulse4     =  900;  // minimum servo position  
int maxPulse4    =  2100; // maximum servo position  
int turnRate3     =  100;  // servo turn rate increment (larger value, faster rate) 
int turnRate4     =  100;
int refreshTime3  =  20;   // time (ms) between pulses (50Hz)  
int refreshTime4  =  20;   // time (ms) between pulses (50Hz)  

int servo5     =  6;    // control pin for servo motor
int servo6     =  7;
int minPulse5     =  900;  // minimum servo position  
int maxPulse5     =  2100; // maximum servo position  
int minPulse6     =  900;  // minimum servo position  
int maxPulse6    =  2100; // maximum servo position  
int turnRate5     =  100;  // servo turn rate increment (larger value, faster rate) 
int turnRate6    =  100;
int refreshTime5  =  20;   // time (ms) between pulses (50Hz)  
int refreshTime6  =  20;   // time (ms) between pulses (50Hz) 

int servo7     =  8;    // control pin for servo motor
int servo8     =  9;
int minPulse7     =  900;  // minimum servo position  
int maxPulse7     =  2100; // maximum servo position  
int minPulse8     =  900;  // minimum servo position  
int maxPulse8     =  2100; // maximum servo position  
int turnRate7     =  100;  // servo turn rate increment (larger value, faster rate) 
int turnRate8     =  100;
int refreshTime7  =  20;   // time (ms) between pulses (50Hz)  
int refreshTime8  =  20;   // time (ms) between pulses (50Hz

int servo9     =  10;    // control pin for servo motor
int servo10     =  11;
int minPulse9     =  900;  // minimum servo position  
int maxPulse9     =  2100; // maximum servo position  
int minPulse10     =  900;  // minimum servo position  
int maxPulse10    =  2100; // maximum servo position  
int turnRate9     =  100;  // servo turn rate increment (larger value, faster rate) 
int turnRate10     =  100;
int refreshTime9  =  20;   // time (ms) between pulses (50Hz)  
int refreshTime10  =  20;   // time (ms) between pulses (50Hz)  

int servo11     =  12;    // control pin for servo motor
int servo12     =  13;
int minPulse11     =  900;  // minimum servo position  
int maxPulse11     =  2100; // maximum servo position  
int minPulse12     =  900;  // minimum servo position  
int maxPulse12    =  2100; // maximum servo position  
int turnRate11     =  100;  // servo turn rate increment (larger value, faster rate) 
int turnRate12    =  100;
int refreshTime11  =  20;   // time (ms) between pulses (50Hz)  
int refreshTime12  =  20;   // time (ms) between pulses (50Hz)  
        
// The Arduino will calculate these values for you -------------------------------------------------------------------------------------------------------------------------------------------------------------
int centerServo;         // center servo position  
int centerServo2;         // center servo position  
int pulseWidth;          // servo pulse width  
int pulseWidth2; 
int moveServo;           // raw user input  
int moveServo2; 
long lastPulse   = 0;    // recorded time (ms) of the last pulse  
long lastPulse2   = 0;    // recorded time (ms) of the last pulse 

int centerServo3;         // center servo position  
int centerServo4;         // center servo position  
int pulseWidth3;          // servo pulse width  
int pulseWidth4; 
int moveServo3;           // raw user input  
int moveServo4; 
long lastPulse3   = 0;    // recorded time (ms) of the last pulse  
long lastPulse4   = 0;    // recorded time (ms) of the last pulse 
  
int centerServo5;         // center servo position  
int centerServo6;         // center servo position  
int pulseWidth5;          // servo pulse width  
int pulseWidth6; 
int moveServo5;           // raw user input  
int moveServo6; 
long lastPulse5   = 0;    // recorded time (ms) of the last pulse  
long lastPulse6   = 0;    // recorded time (ms) of the last pulse 
  
int centerServo7;         // center servo position  
int centerServo8;         // center servo position  
int pulseWidth7;          // servo pulse width  
int pulseWidth8; 
int moveServo7;           // raw user input  
int moveServo8; 
long lastPulse7   = 0;    // recorded time (ms) of the last pulse  
long lastPulse8   = 0;    // recorded time (ms) of the last pulse 

int centerServo9;         // center servo position  
int centerServo10;         // center servo position  
int pulseWidth9;          // servo pulse width  
int pulseWidth10; 
int moveServo9;           // raw user input  
int moveServo10; 
long lastPulse9   = 0;    // recorded time (ms) of the last pulse  
long lastPulse10   = 0;    // recorded time (ms) of the last pulse 
  
int centerServo11;         // center servo position  
int centerServo12;         // center servo position  
int pulseWidth11;          // servo pulse width  
int pulseWidth12; 
int moveServo11;           // raw user input  
int moveServo12; 
long lastPulse11   = 0;    // recorded time (ms) of the last pulse  
long lastPulse12   = 0;    // recorded time (ms) of the last pulse 
     
     
  
void setup() {  
  pinMode(servo1, OUTPUT);  // Set servo pin as an output pin  
  pinMode(servo2, OUTPUT);  // Set servo pin as an output pin 
  pinMode(servo3, OUTPUT);  // Set servo pin as an output pin  
  pinMode(servo4, OUTPUT);  // Set servo pin as an output pin 
  pinMode(servo5, OUTPUT);  // Set servo pin as an output pin  
  pinMode(servo6, OUTPUT);  // Set servo pin as an output pin
  pinMode(servo7, OUTPUT);  // Set servo pin as an output pin  
  pinMode(servo8, OUTPUT);  // Set servo pin as an output pin 
  pinMode(servo9, OUTPUT);  // Set servo pin as an output pin  
  pinMode(servo10, OUTPUT);  // Set servo pin as an output pin 
  pinMode(servo11, OUTPUT);  // Set servo pin as an output pin  
  pinMode(servo12, OUTPUT);  // Set servo pin as an output pin    
  
  centerServo = maxPulse - ((maxPulse - minPulse)/2); 
  centerServo2 = maxPulse2 - ((maxPulse2 - minPulse2)/2);  
  pulseWidth = centerServo;   // Give the servo a starting point (or it floats)  
  pulseWidth2 = centerServo2;   // Give the servo a starting point (or it floats) 
  
  centerServo3 = maxPulse3 - ((maxPulse3 - minPulse3)/2); 
  centerServo4 = maxPulse4 - ((maxPulse4 - minPulse4)/2);  
  pulseWidth3 = centerServo3;   // Give the servo a starting point (or it floats)  
  pulseWidth4 = centerServo4;   // Give the servo a starting point (or it floats) 
  
  centerServo5 = maxPulse5 - ((maxPulse5 - minPulse5)/2); 
  centerServo6 = maxPulse6 - ((maxPulse6 - minPulse6)/2);  
  pulseWidth5 = centerServo5;   // Give the servo a starting point (or it floats)  
  pulseWidth6 = centerServo6;   // Give the servo a starting point (or it floats) 
  
  centerServo7 = maxPulse7 - ((maxPulse7 - minPulse7)/2); 
  centerServo8 = maxPulse8 - ((maxPulse8 - minPulse8)/2);  
  pulseWidth7 = centerServo7;   // Give the servo a starting point (or it floats)  
  pulseWidth8 = centerServo8;   // Give the servo a starting point (or it floats) 
  
 centerServo9 = maxPulse9 - ((maxPulse9 - minPulse9)/2); 
 centerServo10 = maxPulse10 - ((maxPulse10 - minPulse10)/2);  
 pulseWidth9 = centerServo9;   // Give the servo a starting point (or it floats)  
 pulseWidth10 = centerServo10;   // Give the servo a starting point (or it floats) 
  
  centerServo11 = maxPulse11 - ((maxPulse11 - minPulse11)/2); 
  centerServo12 = maxPulse12 - ((maxPulse12 - minPulse12)/2);  
  pulseWidth11 = centerServo11;   // Give the servo a starting point (or it floats)  
  pulseWidth12 = centerServo12;   // Give the servo a starting point (or it floats)

Theres More…

[code Serial.begin(9600);  
  Serial.println("Arduino Serial Servo Control"); 
  Serial.println("        RIGHT LEG           ");
  Serial.println("Press 1 or 2 to move Servo 1"); 
  Serial.println("Press q or w to move Servo 2");
  Serial.println("Press a or s to move Servo 3"); 
  Serial.println("Press z or x to move Servo 4");
  Serial.println("Press e or r to move Servo 5"); 
  Serial.println("Press d or f to move Servo 6");
  Serial.println("    Spacebar to Center");
  Serial.println();
  Serial.println("        LEFT LEG            ");  
  Serial.println("Press 9 or 0 to move Servo 7"); 
  Serial.println("Press o or p to move Servo 8");
  Serial.println("Press k or l to move Servo 9"); 
  Serial.println("Press n or m to move Servo 10");
  Serial.println("Press u or i to move Servo 11"); 
  Serial.println("Press h or j to move Servo 12");
  Serial.println("    Spacebar to Center");
  Serial.println();  
}  
  
void loop() {  
  // wait for serial input  
  if (Serial.available() > 0) {  
    // read the incoming byte:  
    moveServo = Serial.read();  
  
    // '<'      Left, Right, and Center Control       '>'  
    if (moveServo == 1) { pulseWidth = pulseWidth - turnRate; }  
    if (moveServo == 2) { pulseWidth = pulseWidth + turnRate; }  
    if (moveServo == 32) { pulseWidth = centerServo; } 
    
    if (moveServo == 113) { pulseWidth2 = pulseWidth2 - turnRate2; }  
    if (moveServo == 119) { pulseWidth2 = pulseWidth2 + turnRate2; }  
    if (moveServo == 32) { pulseWidth2 = centerServo2; } 
    
    if (moveServo == 97) { pulseWidth3 = pulseWidth3 - turnRate3; }  
    if (moveServo == 115) { pulseWidth3 = pulseWidth3 + turnRate3; }  
    if (moveServo == 32) { pulseWidth3 = centerServo3; }  
    
    if (moveServo == 122) { pulseWidth4 = pulseWidth4 - turnRate4; }  
    if (moveServo == 120) { pulseWidth4 = pulseWidth4 + turnRate4; }  
    if (moveServo == 32) { pulseWidth4 = centerServo4; }  
    
    if (moveServo == 101) { pulseWidth5 = pulseWidth5 - turnRate5; }  
    if (moveServo == 114) { pulseWidth5 = pulseWidth5 + turnRate5; }  
    if (moveServo == 32) { pulseWidth5 = centerServo5; }  
    
    if (moveServo == 100) { pulseWidth6 = pulseWidth6 - turnRate6; }  
    if (moveServo == 102) { pulseWidth6 = pulseWidth6 + turnRate6; }  
    if (moveServo == 32) { pulseWidth6 = centerServo6; }  
    
    if (moveServo == 9) { pulseWidth7 = pulseWidth7 - turnRate7; }  
    if (moveServo == 0) { pulseWidth7 = pulseWidth7 + turnRate7; }  
    if (moveServo == 32) { pulseWidth7 = centerServo7; } 
    
    if (moveServo == 111) { pulseWidth8 = pulseWidth8 - turnRate8; }  
    if (moveServo == 112) { pulseWidth8 = pulseWidth8 + turnRate8; }  
    if (moveServo == 32) { pulseWidth8 = centerServo8; } 
    
    if (moveServo == 107) { pulseWidth9 = pulseWidth9 - turnRate9; }  
    if (moveServo == 108) { pulseWidth9 = pulseWidth9 + turnRate9; }  
    if (moveServo == 32) { pulseWidth9 = centerServo9; }  
    
    if (moveServo == 110) { pulseWidth10 = pulseWidth10 - turnRate10; }  
    if (moveServo == 109) { pulseWidth10 = pulseWidth10 + turnRate10; }  
    if (moveServo == 32) { pulseWidth10 = centerServo10; }  
    
    if (moveServo == 117) { pulseWidth11 = pulseWidth11 - turnRate11; }  
    if (moveServo == 105) { pulseWidth11 = pulseWidth11 + turnRate11; }  
    if (moveServo == 32) { pulseWidth11 = centerServo11; }  
    
    if (moveServo == 104) { pulseWidth12 = pulseWidth12 - turnRate12; }  
    if (moveServo == 106) { pulseWidth12 = pulseWidth12 + turnRate12; }  
    if (moveServo == 32) { pulseWidth12 = centerServo12; } 
    
    
    
    // stop servo pulse at min and max---------------------------------------------------------------------------------------------------  
    if (pulseWidth > maxPulse) { pulseWidth = maxPulse; }  
    if (pulseWidth < minPulse) { pulseWidth = minPulse; } 
    
    if (pulseWidth2 > maxPulse2) { pulseWidth2 = maxPulse2; }  
    if (pulseWidth2 < minPulse2) { pulseWidth2 = minPulse2; }
 
    if (pulseWidth3 > maxPulse3) { pulseWidth3 = maxPulse3; }  
    if (pulseWidth3 < minPulse3) { pulseWidth3 = minPulse3; } 
    
    if (pulseWidth4 > maxPulse4) { pulseWidth4 = maxPulse4; }  
    if (pulseWidth4 < minPulse4) { pulseWidth4 = minPulse4; }   
  
    if (pulseWidth5 > maxPulse5) { pulseWidth5 = maxPulse5; }  
    if (pulseWidth5 < minPulse5) { pulseWidth5 = minPulse5; } 
    
    if (pulseWidth6 > maxPulse6) { pulseWidth6 = maxPulse6; }  
    if (pulseWidth6 < minPulse6) { pulseWidth6 = minPulse6; }   
     
    if (pulseWidth7 > maxPulse7) { pulseWidth7 = maxPulse7; }  
    if (pulseWidth7 < minPulse7) { pulseWidth7 = minPulse7; } 
    
    if (pulseWidth8 > maxPulse8) { pulseWidth8 = maxPulse8; }  
    if (pulseWidth8 < minPulse8) { pulseWidth8 = minPulse8; }
 
    if (pulseWidth9 > maxPulse9) { pulseWidth3 = maxPulse9; }  
    if (pulseWidth9 < minPulse9) { pulseWidth3 = minPulse9; } 
    
    if (pulseWidth10 > maxPulse10) { pulseWidth10 = maxPulse10; }  
    if (pulseWidth10 < minPulse10) { pulseWidth10 = minPulse10; }   
  
    if (pulseWidth11 > maxPulse11) { pulseWidth11 = maxPulse11; }  
    if (pulseWidth11 < minPulse11) { pulseWidth11 = minPulse11; } 
    
    if (pulseWidth12 > maxPulse12) { pulseWidth12 = maxPulse12; }  
    if (pulseWidth12 < minPulse12) { pulseWidth12 = minPulse12; }   
     
     //print pulseWidth back to the Serial Monitor (uncomment to debug)  
     //Serial.print("Pulse Width: ");  
     //Serial.print(pulseWidth);  
     //Serial.println("us");   // microseconds  
  }  
  
  // pulse the servo every 20 ms (refreshTime) with current pulseWidth  
  // this will hold the servo's position if unchanged, or move it if changed  
  if (millis() - lastPulse >= refreshTime) {  
    digitalWrite(servo1, HIGH);   
    delayMicroseconds(pulseWidth);  
    digitalWrite(servo1, LOW);    
    lastPulse = millis();           
  }  
  if (millis() - lastPulse2 >= refreshTime2) {  
    digitalWrite(servo2, HIGH);   
    delayMicroseconds(pulseWidth2);  
    digitalWrite(servo2, LOW);   
    lastPulse2 = millis();          
  }  
   if (millis() - lastPulse3 >= refreshTime3) {  
    digitalWrite(servo3, HIGH);   
    delayMicroseconds(pulseWidth3);  
    digitalWrite(servo3, LOW);   
    lastPulse3 = millis();          
  }  
   if (millis() - lastPulse4 >= refreshTime4) {  
    digitalWrite(servo4, HIGH);   
    delayMicroseconds(pulseWidth4);  
    digitalWrite(servo4, LOW);   
    lastPulse4 = millis();          
  }  
   if (millis() - lastPulse5 >= refreshTime5) {  
    digitalWrite(servo5, HIGH);   
    delayMicroseconds(pulseWidth5);  
    digitalWrite(servo5, LOW);   
    lastPulse5 = millis();          
  }  
   if (millis() - lastPulse6 >= refreshTime6) {  
    digitalWrite(servo6, HIGH);   
    delayMicroseconds(pulseWidth6);  
    digitalWrite(servo6, LOW);   
    lastPulse6 = millis();          
  }  
  if (millis() - lastPulse7 >= refreshTime7) {  
    digitalWrite(servo7, HIGH);   
    delayMicroseconds(pulseWidth7);  
    digitalWrite(servo7, LOW);    
    lastPulse7 = millis();           
  }  
  if (millis() - lastPulse8 >= refreshTime8) {  
    digitalWrite(servo8, HIGH);   
    delayMicroseconds(pulseWidth8);  
    digitalWrite(servo8, LOW);   
    lastPulse8 = millis();          
  }  
   if (millis() - lastPulse9 >= refreshTime9) {  
    digitalWrite(servo9, HIGH);   
    delayMicroseconds(pulseWidth9);  
    digitalWrite(servo9, LOW);   
    lastPulse9 = millis();          
  }  
   if (millis() - lastPulse10 >= refreshTime10) {  
    digitalWrite(servo10, HIGH);   
    delayMicroseconds(pulseWidth10);  
    digitalWrite(servo10, LOW);   
    lastPulse10 = millis();          
  }  
   if (millis() - lastPulse11 >= refreshTime11) {  
    digitalWrite(servo11, HIGH);   
    delayMicroseconds(pulseWidth11);  
    digitalWrite(servo11, LOW);   
    lastPulse11 = millis();          
  }  
   if (millis() - lastPulse12 >= refreshTime12) {  
    digitalWrite(servo12, HIGH);   
    delayMicroseconds(pulseWidth12);  
    digitalWrite(servo12, LOW);   
    lastPulse12 = millis();          
  }  
}  ]

I’m really just defining everything 12 times, is there anything i don’t need…?
I am a total novice when it comes to arduino…

Any particular reason you're not using the servo library?

What might cause some problems though is that you are sleeping for 1-2 ms while telling the servo where it sould be. With 12 that's between 12-24 ms. That might throw your timings off..ß

Also you are reading the setting lastUpdate after waiting, probably not critical but should be before.

Would recommend you clean up your code a bit by using arrays and the servo library. ( Servo - Arduino Reference )

Haha thanks, could try that, but I am a total novice when it comes to Arduino coding.
I found this sample on the internet, and really all I did was copy it 12 times...