Stepper motor attached with 3 micro switches to do 3 different commands

Hi all,

Im having trouble telling my stepper motor to go clockwise continually until it hits a micro switch that then turns it anticlockwise to a home micro switch which turns it off.

3 different micro switches are attached to the Arduino along with the STEP and DIR pin from the easy driver. The easy driver has 12V going through it also the 4 cables from the motor.

Im trying to use the micros switches as a toggle switch which I believe is achieved with the first 2 lines of code under void loop.

I am able to run the motor continually with no switches on the circuit or the code that is attached now but when I try to put switches on and the code it doesn't want to play ball

The first of the micro switches i'm using is to start the motor rotating clockwise.
The second is to stop the motor for 1 second and then is to revers the motor rotating anticlockwise.
Finally the third is to stop the motor.

If anyone knows where my code is going wrong or what I need to do in order to make this system function as I need it would be greatly appreciated.


stepper motor JK42hm34-1334

A3967 easy driver

Micro switches

Read the how to use this forum stickies to see how to properly post code.

How are the switches wired?

DO you have pull-up or pull-down resistors on the pins connected to the switches?

Why do have #defines for all the pins and then never use them?


it doesn't want to play ball

  1. More details would be better.

  2. Use code tags or many people will ignore you.

  3. For this

 // motor reverse
 {   delay (1000);
  if (digitalRead (onPin) == HIGH && lastButton == LOW)

you probably meant

 // motor reverse
 {   delay (1000);
  if (digitalRead (endPin) == HIGH && lastButton == LOW)
  1. I would structure the code to have a motor movement function and some button read functions. You main loop then reads buttons and moves the motor (or not) based on the results.