Autonomous "sweep" robot arm code

I’m trying to make a robot arm basically show off by making it sweep in different directions. I promise I have everything hooked up right, I still can’t get this to work for some reason though. Here’s my code:

#include <Servo.h>

// "//" dictates a single line comment. Anything following a double slash doesn't affect the operation of the robot arm

int pos1; //the variable that "stores" the position of the servo
int pos2;
int pos3;
int pos4;
int pos5;
int pos6;
int pos7;

//Servo related pre-loop setup

Servo base;
Servo shoulder1;
Servo shoulder2;
Servo elbow;
Servo wristy;
Servo wristx;
Servo claw;

void setup ()

{
  //Servo related void setup
  base.attach (2);
  shoulder1.attach (3);
  shoulder2.attach (4);
  elbow.attach (5);
  wristy.attach (6);
  wristx.attach (7);
  claw.attach (8);
}

void loop ()

{

  for (pos1 = 0; pos1 < 90; pos1 += 1) //tells the servo to go from 0 to 180 degress in steps of 1 degree
  {
    shoulder1.write (pos1); //tells the servo to go to its postition
    delay(45); //gives the servo time to get there
  }
  for (pos1 = 90; pos1 >= 1; pos1 -= 1)
  {
    shoulder1.write (pos1);
    delay(45);
  }



  for (pos2 = 90; pos2 < 0; pos2 += 1)
  {
    shoulder2.write (pos2);
    delay(45);
  }
  for (pos2 = 0; pos2 >= 1; pos2 -= 1)
  {
    shoulder2.write (pos2);
    delay(45);
  }



  for (pos3 = 100; pos3 < 0; pos3 += 1)
  {
    elbow.write (pos3);
    delay(45);
  }
  for (pos3 = 0; pos3 >= 1; pos3 -= 1)
  {
    elbow.write (pos3);
    delay(45);

  }



  for (pos4 = 100; pos4 < 0; pos4 += 1)
  {
    wristy.write (pos4);
    delay(45);
  }
  for (pos4 = 0; pos4 >= 1; pos4 -= 1)
  {
    wristy.write (pos4);
    delay(45);
  }



  for (pos5 = 60; pos5 < 120; pos5 += 1)
  {
    base.write (pos5);
    delay(100);
  }
  for (pos5 = 120; pos5 >= 1; pos5 -= 1)
  {
    base.write (pos5);
    delay(100);
  }



  for (pos6 = 70; pos6 < 110; pos6 += 1)
  {
    claw.write (pos6);
    delay(45);
  }
  for (pos6 = 110; pos6 >= 1; pos6 -= 1)
  {
    claw.write (pos6);
    delay(45);
  }

}

All that happens when I load this onto my arduino (Due) is the elbow goes up and down once, then the base turns in one direction, starts turning in the other direction and then doesn’t stop.

Thanks in advance

I just noticed my error. When a for loop starts it doesn't stop until it's complete. How could I make all these loops run at once?

There is NO reason for pos1, pos2, etc. to be global.

Your loop() should contain code to move ONE servo at a time. Make sure each servo is working alone, Then, think about combining them.

How are you powering the servos?

I can get each servo working independently, I just can’t get them working together. I’d be fine with either all of them moving at the same time or one motor going back and forth, then the next, then the next, and so on.

I’m powering them with a 5v 8a supply, why?

I'm powering them with a 5v 8a supply, why?

Because trying to power them with the Arduino is a symptom of the problems you are seeing. I wanted to eliminate power as an issue.

If one servo at a time works, try two. Then three. See where the problems start.

I tried one, then I added a second and the second did nothing bu tthe first kept going.

then I added a second

But posted no code.

and the second did nothing bu tthe first kept going.

Fancy footwork, but no real help. Use names that are in the code!