Dear backbone,
I am trying to work a somehow similar project as yours but I am facing difficulties and it would be great if you could help with an advice. I am trying to operate a valve driven by a small stepper using Uno and EasyDrive board. At the closed position the valve hits a limit switch. I am using a another switch to tell the valve to open (.i.e. motor CW) or close (i.e. motor CCW). I would like to implement the following logic: In case an open command is received the motor should turn 8000 steps to one side. In case a close command is received the motor should turn 8000 steps to the other side (-8000). Then, in case the limit switch is not activated I would like to turn an additional (-1000) steps. I would like to use AccelStepper library because I plan to operate more than one valve in parallel.
Anyhow the code without the limit switch seems to work fine, but I am not able to make the limit switch to work see below:
void loop ( ) {
cmdVent = digitalRead (cmdPinVent); //Read the Vent Valve command to OPEN (LOW) or to CLOSE (HIGH)
if (ventValve1.distanceToGo ( ) == 0) {
//Check for OPEN command
if ( cmdVent == LOW && cmdVentOld == HIGH ) {
ventValve1.move (stepNumber);
cmdVentOld = cmdVent;
}
//Check for CLOSE command
if ( cmdVent == HIGH && cmdVentOld == LOW) {
ventValve1.move (-stepNumber);
cmdVentOld = cmdVent;
switchVent1=digitalRead (switchPinVent1);
if (switchVent1 != HIGH) {
ventValve1.move (-1000);
}
}
}
ventValve1 .run( );
}
Base on your experience with the AccelStepper library, do you have and advice on how to sort this out?
Thank you,
Morel