Stepper motor direction control with one relay

Good day,
Please assist. I able to control direction of a stepper motor using 2 relays thus engaging one turns the motor clockwise and activating another turns the motor anti-clockwise.

I have a challenge with using only one relay. The motor should be in a off state but monitoring an input. When the relay state goes Normally close it should turn the motor for a specified number of turns clockwise then stop and go into a off state again.
It should then monitor the relay state again until the state of relay goes normally open. It then needs to turn the motor anti-clockwise for a specified number of turns then stop and monitor the state of the relay.

Is someone able to guide me on the programming as this is new to me thanks.

The diagram of current 2 relay system is attached.

58e029dcd8add7c316f8cd76214abbc8d2bb6b00.jpg

But, I don't see any relays...

That driver board has step and direction inputs. Why would you need a relay?

...R
Stepper Motor Basics
Simple Stepper Code

I am getting an external trigger from relay from an existing platform.

So, the switches are actually relays aka gives the input?

In that case, it doesn't really matter if they are switches or relays. But instead of detecting the state of the input, detect if it changed. When it changes to low, run clockwise for x seconds. When it changes to high, run counter clockwise for x seconds. Google "for state change. Or, it you want easy. grab a library like Bounce2 :slight_smile:

StateChangeDetection example in examples 02 Digital

Freddie911:
I am getting an external trigger from relay from an existing platform.

You are not letting us know the full story.

Make a simple drawing showing all the connections from all the devices and post a photo of the drawing.

If the relay is functionally equivalent to a push-button connected to the Arduino then you just need a variable that keeps track of the state - fwd or rev - and it should change whenever the relay contacts close (having checked that they have opened in between times).

...R