Problem Programming L293D with Dual Motors

//


int in1pin = 6; 
int in2pin = 7;
int in3pin = 4;
int in4pin = 5;
//motor controller

int leftButton = 9;
int rightButton = 8;
int upButton = 13;
int downButton = 12;
//buttons

 

void setup()
{
  pinMode(in1pin, OUTPUT);
  pinMode(in2pin, OUTPUT);
  pinMode(in3pin, OUTPUT);
  pinMode(in4pin, OUTPUT);
  
  pinMode(leftButton, INPUT_PULLUP);
  pinMode(rightButton, INPUT_PULLUP);
  pinMode(upButton, INPUT_PULLUP);
  pinMode(downButton, INPUT_PULLUP); //inputs w internal pullup resistors
  
  digitalWrite(in1pin, LOW); // nothing happens
  digitalWrite(in2pin, LOW);
  digitalWrite(in3pin, LOW);
  digitalWrite(in4pin, LOW);
}

void loop()
{
  int leftPinState = digitalRead(leftButton);
  int rightPinState = digitalRead(rightButton); 
  int upPinState = digitalRead(upButton);
  int downPinState = digitalRead(downButton);
  
  if (leftPinState == LOW) { // if left button is pressed ... 

    digitalWrite(in1pin, HIGH); // turn Azimuth motor left
    digitalWrite(in2pin, LOW);
    digitalWrite(in3pin, LOW);
    digitalWrite(in4pin, LOW);
  }

  else if (rightPinState == LOW) { // if right button is pressed ...

    digitalWrite(in1pin, LOW);
    digitalWrite(in2pin, HIGH); // turn Azimuth motor right
    digitalWrite(in3pin, LOW);
    digitalWrite(in4pin, LOW);
    
  }
  else if(upPinState == LOW) {
	
    digitalWrite(in1pin, LOW);
    digitalWrite(in2pin, LOW);
    digitalWrite(in3pin, HIGH); // Turn elevation motor up
    digitalWrite(in4pin, LOW);
  
  }
  
  else if(downPinState == LOW) {
   
    digitalWrite(in1pin, LOW);
    digitalWrite(in2pin, LOW);
    digitalWrite(in3pin, LOW); 
    digitalWrite(in4pin, HIGH);// Turn elevation motor 
  }
  
  else { // if neither button is pressed ...

    digitalWrite(in1pin, LOW); // nothing happens
    digitalWrite(in2pin, LOW);
    digitalWrite(in3pin, LOW);
    digitalWrite(in4pin, LOW);
    
  }
  
  
  }
  
  
  

![Capture|498x500](upload://vQt9I7YtOgNgR1yxUve2rgIsv4Z.png)

Are you going to tell us the problem?

For help, please post a wiring diagram, a link to the motor product page and a description of the problem.

The L293D is an ancient, weak and inefficient motor driver, useful only for small motors.

This looks like a single axis control telescope mount,
without end stops and prioritized control buttons.

I see nothing like EN in the sketch, but that could be wired to be enabled.

There is no obvious problem with the sketch, I would have used some functions,
but if single axis movement is ok, the sketch should work.

const uint8_t in1pin = 6;
const uint8_t in2pin = 7;
const uint8_t in3pin = 4;
const uint8_t in4pin = 5;

const uint8_t azimuthLeftButtonPin = 9;
const uint8_t azimuthRightButtonPin = 8;
const uint8_t elevationUpButtonPin = 13;
const uint8_t elevationDownButtonPin = 12;

void setup() {
  pinMode(in1pin, OUTPUT);
  pinMode(in2pin, OUTPUT);
  pinMode(in3pin, OUTPUT);
  pinMode(in4pin, OUTPUT);

  pinMode(azimuthLeftButtonPin, INPUT_PULLUP);
  pinMode(azimuthRightButtonPin, INPUT_PULLUP);
  pinMode(elevationUpButtonPin, INPUT_PULLUP);
  pinMode(elevationDownButtonPin, INPUT_PULLUP);

  motorControl(0);  // all off
}

// select active channels via bits in a byte
void motorControl(uint8_t mask) {
  digitalWrite(in1pin, mask & 8 ? HIGH : LOW);
  digitalWrite(in2pin, mask & 4 ? HIGH : LOW);
  digitalWrite(in3pin, mask & 2 ? HIGH : LOW);
  digitalWrite(in4pin, mask & 1 ? HIGH : LOW);
}

bool pressed(uint8_t pin) {
  return digitalRead(pin) == LOW;
}

void loop() {
  if (pressed(azimuthLeftButtonPin)) {
    motorControl(8);
  } else if (pressed(azimuthRightButtonPin)) {
    motorControl(4);
  } else if (pressed(elevationUpButtonPin)) {
    motorControl(2);
  } else if (pressed(elevationDownButtonPin)) {
    motorControl(1);
  } else {
    motorControl(0);
  }
}

Motor used

You will need a motor driver like one of these for that ~ 1 kW motor.
https://www.robotshop.com/en/high-power-motor-controllers.html
Choose one rated for at least 40 Ampere continuous current.