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.
}