Forwards and Backwards, Stepper Motor, CNC Sheild, Trying to limit void loop() from continuously looping

I am trying to make a DIY watch cleaning machine. I am using an Arduino Uno, a CNC Sheild and 3 three NEMA 17 bipolar stepper motors. My sequence for this machine is to lower a basket into a jar of cleaning solution, agitate it for 5 minutes, raise the basket out of the jar halfway, do a full spin for 1 minute, raise it again fully out of the jar, and lastly have the carousel table rotate 90 degrees. Lastly have this sequence start over again for two more times.

My problem is I don't know how to set a specific time limit for the agitating and spin cycle and finally ending the sequence after 3 cycles. I am sure that there are many creative ways to do this, but I have no clue.

Does anyone have any suggestions on how to do this. I am a noob at C++ programing and if you do give suggestion, please give examples because I can understand the logic much easier this way.

My program so far:


const int stepCarousel = 2;
const int dirCarousel = 5;
const int stepAgitator = 3;
const int dirAgitator = 6;
const int stepLinearActuator = 4;
const int dirLinearActuator = 7;

void setup(){
  pinMode(stepCarousel, OUTPUT);
  pinMode(dirCarousel, OUTPUT);
  pinMode(stepAgitator, OUTPUT);
  pinMode(dirAgitator, OUTPUT);
  pinMode(stepLinearActuator, OUTPUT);
  pinMode(dirLinearActuator, OUTPUT);
}

void loop() {  
//Linear Actuator for lowering basket into jar.
digitalWrite(dirLinearActuator, HIGH); // motor moves actuator down.
  for (int i = 0; i < 10000; i++) {
    digitalWrite(stepLinearActuator, HIGH);
    delayMicroseconds(1000);
    digitalWrite(stepLinearActuator, LOW);
    delayMicroseconds(1000);
  }
  delay(1000); // delays for one second.

  // Agitator for Basket in jar of cleaning solution for 5 minutes
  digitalWrite(dirAgitator, LOW); // motor moves clockwise.
  for (int i = 0; i < 200; i++) {
    digitalWrite(stepAgitator, HIGH);
    delayMicroseconds(1000);
    digitalWrite(stepAgitator, LOW);
    delayMicroseconds(1000);
  }
  delay(1000); // delays for one second.

  digitalWrite(dirAgitator, HIGH); //motor moves counterclockwise.
  for (int i = 0; i < 200; i++) {
    digitalWrite(stepAgitator, HIGH);
    delayMicroseconds(1000);
    digitalWrite(stepAgitator, LOW);
    delayMicroseconds(1000);
  }
  delay(1000); // delays for one second.

  digitalWrite(dirAgitator, LOW); // motor moves clockwise.
  for (int i = 0; i < 200; i++) {
    digitalWrite(stepAgitator, HIGH);
    delayMicroseconds(1000);
    digitalWrite(stepAgitator, LOW);
    delayMicroseconds(1000);
  }
  delay(1000); // delays for one second.

  digitalWrite(dirAgitator, HIGH); // motor moves counterclockwise.
  for (int i = 0; i < 200; i++) {
    digitalWrite(stepAgitator, HIGH);
    delayMicroseconds(1000);
    digitalWrite(stepAgitator, LOW);
    delayMicroseconds(1000);
  }
  delay(1000); // delays for one second.

  // Linear Actuator raising basket halfway out of jar.
  digitalWrite(dirLinearActuator, LOW); // motor moves actuator up.
  for (int i = 0; i < 3000; i++) {
    digitalWrite(stepLinearActuator, HIGH);
    delayMicroseconds(1000);
    digitalWrite(stepLinearActuator, LOW);
    delayMicroseconds(1000);
  }
  delay(1000); // delays for one second.

  // Spin Basket halfway out of jar for 1 minutes
  digitalWrite(dirAgitator, LOW); // motor moves clockwise.
  for (int i = 0; i < 10000; i++) {
    digitalWrite(stepAgitator, HIGH);
    delayMicroseconds(1000);
    digitalWrite(stepAgitator, LOW);
    delayMicroseconds(1000);
  }
  delay(1000); // delays for one second.

   // Linear Actuator raising basket fully out of jar.
  digitalWrite(dirLinearActuator, LOW); // motor moves actuator up.
  for (int i = 0; i < 7000; i++) {
    digitalWrite(stepLinearActuator, HIGH);
    delayMicroseconds(1000);
    digitalWrite(stepLinearActuator, LOW);
    delayMicroseconds(1000);
  }
  delay(1000); // delays for one second.
 
  // Stepper moto moves careousel table to next cycle.
  digitalWrite (dirCarousel, HIGH); // motor moves carousel counterclockwise.
  for (int i = 0; i < 200; i++) {
    digitalWrite(stepCarousel, HIGH);
    delayMicroseconds(1000);
    digitalWrite(stepCarousel, LOW);
    delayMicroseconds(1000);
  }
  delay(1000); // delays for 1 second.
}

Welcome

Why does no one read the rules before posting?

Read the forum guidelines to see how to properly post code and some good information on making a good post.

Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Pleasde go back and fix your original post.

Non-blocking timing tutorials:
Blink without delay().
Beginner's guide to millis().
Several things at a time.

I am new to posting. I hope everything looks fine now. Thanks for the suggestions I will look them up.

Can you use a library to help make things easier? I like the MobaTools stepper library.

This is a good place for a state machine.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.