Prioritize IF statements

Hello all

I am using a 28BYJ-48 stepper motor with a ULN2003 driver with a 3 position switch and arduino UNO. My aim is to have the switch control direction in position 1 and 2 and when the switch is in the middle (position 3) for the motor to stop.

i am getting some very weird actions from the code/ hardware and was hoping someone could help point me in the right direction to narrow this down so i can get this running!!

the reactions are:

  1. it seems to randomly pick if statements no matter the position of the switch. How can i prioritize if statments?
  2. when it does run, the motor only turns a quarter and then stops with 2 of the lights on the uln2003 driver stay on.

any help will be greatly appreaciated

//#include <AccelStepper.h>
#include <Stepper.h>

//Motor Pins
int stepIN1Pin = 8;         
int stepIN2Pin = 9;
int stepIN3Pin = 10;
int stepIN4Pin = 11;
int _step = 0; 
boolean dir = true;// gre

//Rotary Switch
//D = Common
int button1Pin = 5; //10 Anticlockwise
int button2Pin = 6; //11 STOP
int button3Pin = 7; //12 Clockwise

int stepsPerRevolution = 2048; // amount of steps per revolution

Stepper myStepper(stepsPerRevolution, stepIN1Pin, stepIN3Pin, stepIN2Pin, stepIN4Pin);

void setup() {

 pinMode(stepIN1Pin, OUTPUT);  
 pinMode(stepIN2Pin, OUTPUT);  
 pinMode(stepIN3Pin, OUTPUT);  
 pinMode(stepIN4Pin, OUTPUT);  

 pinMode(button1Pin, INPUT);
 pinMode(button2Pin, INPUT);
 pinMode(button3Pin, INPUT);

void loop() {
  int button1State, button2State, button3State;
  button1State = digitalRead(button1Pin);
  button2State = digitalRead(button2Pin);
  button3State = digitalRead(button3Pin);

 if ((button1State == HIGH) && (button2State, button3State == LOW)){

 if ((button3State == HIGH) && (button2State, button1State == LOW)){
     digitalWrite(stepIN1Pin, LOW);  
     digitalWrite(stepIN2Pin, LOW); 
     digitalWrite(stepIN3Pin, LOW); 
     digitalWrite(stepIN4Pin, LOW); 

 if ((button2State == HIGH) && (button1State, button3State == LOW)){


How are things wired? Without a pullup or pulldown resistor, the buttons will act very strangely. Instead of a pin mode of INPUT, it might be better to use INPUT_PULLUP.

Thank you for your help. Unfortunately it did not work.

I ended up stripping the wiring out and starting again. It now works!!!!! must have been wired incorrectly.

i have a few things left to add to the code to adjust the speed and limit the number of turns.