adafruit motor shield l293d control stepper motor via swithces

hello dear all,
currently i am working on controlling stepper motor using adafruit motor shield l293dand two switch, but i don’t what is the problem since it is not working.
i want to move the stepper forward when i switch the first switch and backward when i switch the secound switch and off when both switchs off.
any help please

here is my code

#include <AFMotor.h>

const int buttonPin1 = 7;
const int buttonPin2 = 8;

// to motor port #2 (M3 and M4)
AF_Stepper motor(48, 2);
int buttonState1 = 0;
int buttonState2 = 0;
void setup() {
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
motor.step(100, OUTPUT, SINGLE);
Serial.begin(9600);
motor.setSpeed(100); // 10 rpm
}
void loop() {
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
motor.setSpeed(100); // 10 rpm

if(buttonState1 == HIGH && buttonState2 == LOW ){
motor.step(100, FORWARD, SINGLE);

delay(.01);
}
else if(buttonState2 == HIGH &&buttonState1 == LOW ){

motor.step(100, BACKWARD, SINGLE);

delay(.01);
}
if
(buttonState2 == LOW &&buttonState1 == LOW ){

motor.step(100, RELEASE, SINGLE);

delay(.01);

}

delay(5);}

Hi and welcome,

pls read the forum rules/instructions (see link in my signature).
→ Place your code in code tags </>.

That said, if you want us to help you, we need:
A schematic of your project (Arduino with shield, button, motor, power supply and the wiring of the devices)

:slight_smile: :slight_smile: :slight_smile: :slight_smile:

Nice, but that won't get us/you any step further ..

You would do better to connect your buttons between GND and the input pins, then;

  pinMode(buttonPin1, INPUT_PULLUP);
  pinMode(buttonPin2, INPUT_PULLUP);
void loop(){

  if(buttonState1 == LOW && buttonState2 == HIGH ){ // reverse button logic, HIGH --> LOW