I'm doing a project on 7 stepper motors where each motor steps one step every 7 minutes.
my problem that I need to keep the stepper at its position during the delay period and I can't achieve this using delay () command because the power go off while using delay ().
I need your help my friends.
here is my code and I'm using Arduino mega .
#include <Stepper.h>
const int stepsPerRevolution = 200;
Stepper myStepper1(stepsPerRevolution, 22,23,24,25);
Stepper myStepper2(stepsPerRevolution, 26,27,28,29);
Stepper myStepper3(stepsPerRevolution, 30,31,32,33);
Stepper myStepper4(stepsPerRevolution, 34,35,36,37);
Stepper myStepper5(stepsPerRevolution, 38,39,40,41);
Stepper myStepper6(stepsPerRevolution, 42,43,44,45);
Stepper myStepper7(stepsPerRevolution, 46,47,48,49);
int stepCount = 0; // number of steps the motor has taken
void setup() {
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
// step one step:
myStepper1.step(1);
delay(3000);
myStepper2.step(1);
delay(3000);
myStepper3.step(1);
delay(3000);
myStepper4.step(1);
delay(3000);
myStepper5.step(1);
delay(3000);
myStepper6.step(1);
delay(3000);
myStepper7.step(1);
Serial.print("steps:" );
Serial.println(stepCount);
stepCount++;
delay(420000);
}
delay(420000);probably fails, you should write delay(420000L); - the "L" makes sure the compiler does not reduce it to an int. (You may want to add a comment // 7minutes wait - for clarity)
I do not understand "because the power go off while using delay ()".
Are you asking for what to do if the power dies "unexpectedly"? Then look at EEPROM to write your Step value into the first 4 memory bytes, and retrieve this value on power up.
Or is something in your driver electronics shutting power down after inactivity? In that case there is little you can do in the program
the meaning of the project is to keep the steppers at the same position then stepping one step every 7 mins.
what I mean that I've coupled the steppers to heavy load so what I observed that the stepper can't keep its position (braking) during the delay time so it moves with the load's torque.