Help with a Solution

Good day all!

I am working on a project, that is currently an idea.

I will be using a stepper motor and driver, the driver has start and stop functions that are activated with a 5VDC pulse. I am wanting to use the Arduino to handle the timing. I will be using a flexible shaft switch, here is where I am thinking there will be an issue.

When the switch is activated, the Arduino will send a 5VDC pulse to the driver, stopping the motor and starting the timer. Once the time has lapsed, the arduino will send another 5VDC pulse to the start pin on the driver. This is where I think there will be issue as the switch will still be held LOW when the time lapses the arduino will be sending the 5VDC and the driver will not start again.

I figure there is a way to reset or "break" away from the loop and allow the program to continue on until the switch is tripped again.

Any advice that you all offer is greatly appreciated.



I have an idea, not sure if it makes sense to do it this way, but appears it could work. I would store the switch state in a variable, once the time has lapsed read the switch state again and compare with the previous. I would then send a 5V pulse to the driver if the two reads are HIGH/HIGH and if it is HIGH/LOW do nothing.

Does this seem to make sense?

Getting an Arduino to control a motor via a motor driver is straightforward as is building logic to handle timings.
I'm not sure, however, about your description of a flexible shaft switch. Is is a momentary switch (like a bell push) or does it toggle to alternate between open contacts and closed contacts, or what ?

It is always possible to make an Arduino react only to a change of the switch position say from closed to open or from open to closed.

These links may help

Stepper Motor Basics
Simple Stepper Code

It will be much easier to help if you make your question specific and post the code you are using.

Also post a link to the datasheets for the stepper motor and for the stepper motor driver.


Have a look at the StateChangeDetection eample. Start your timed sequence whenever the button changes from inactive to active state.

Thanks for the replies.

The flexible shaft switch is just a NO switch.

I am using the driver linked below.


I have not actually starting writing the code yet, I am still in the idea stage. I understand that the Arduino will basically be a pulse controller , as that is what the driver needs to function.

I did load a sample code that I found that just rotated the stepper in one direction, paused, and then the other direction.

I understand and have worked with buttons and switches. The pulse control is what I seem to be having a hard time wrapping my brain around.

Like I stated above, I need the motor to rotate until the limit is activated, delay, and then restart until it activates the limit again, and then continue the cycle.

Like I stated above, I need the motor to rotate until the limit is activated, delay, and then restart until it activates the limit again, and then continue the cycle.

In simple terms that is done with something like this pseudo code

is the limit switch pressed?
  if not - 
    move one step
    start the timing interval
if the stepper is stopped and the timing interval has expired
  start over

Have a go at writing the code and if you can’t get it to work post your best attempt. That will make it much easier to see what you are having trouble with. The second example in my Simple Stepper Code could be a suitable starting point.


I have difficulty to visualise mechanically how this is arranged but since you haven't mentioned a motor reversal and have only one 'limit' switch, I could imagine that the motor rotates in the same direction and the switch is an index switch which indicates that the shaft has completed one revolution.

Anyway, cycle would be something like:


loop() {

if ( switch pulse received, that is OFF -> ON or ON -> OFF transition - debounced) {
stop motor (if running )
start timer

if ( timer expired ) {
start motor ( if not running )


Creating pulses can be done with a timer. You can set a frequency and duty cycle, you can set a pulse counter and stop when a pulse limit has been reached etc. Look at, say, timer1

I was typing this as I got the yellow card indicating that Robin2 got there first, so you have a couple of similar suggestions.