DC motor control With H-Bridge board

Hi all!
I'm trying to Run a 24V motor with the following Motor control board:

For the wiring i have the following setup:

For the programming i created the following:

int switch1 = 2; // switch 1 connected to digital pin 2
int switch2 = 4; // switch 2 connected to digital pin 4
int pwmPin = 11; // PWM1 of IRF3205 module connected to digital pin 11
int dirPin = 12; // DIR1 of IRF3205 module connected to digital pin 12

void setup() {
  pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output.
  pinMode(switch1, INPUT); // switch 1 as input
  pinMode(switch2, INPUT); // switch 2 as input
  pinMode(pwmPin, OUTPUT); // PWM1 as output
  pinMode(dirPin, OUTPUT); // DIR1 as output
}

void loop() {
  if (digitalRead(switch1) == HIGH && digitalRead(switch2) == LOW) {
    digitalWrite(dirPin, LOW); // change direction to left
    analogWrite(pwmPin, 255); // set PWM value to max (255)
  }
  else if (digitalRead(switch2) == HIGH && digitalRead(switch1) == LOW) {
    digitalWrite(dirPin, HIGH); // change direction to right
    analogWrite(pwmPin, 255); // set PWM value to max (255)
  }
  else {
    analogWrite(pwmPin, 0); // set PWM value to 0 to stop the motor
  }
}

When eliminating the Arduino and operating the motor control board directly with the external 5V Power source and variable power source, the motor spins and it all works nicely.

After checking the wiring and code multiple times it left me out of new ideas to find the problem. :stuck_out_tongue:

I hope some fresh eyes and bright minds on this forum can give me some sew insights. Thanks in advance for your input.

You have those two (Right and Left) switches floating? No resistor in your diagram or input_pullup in your code?

Wire the swiches to ground and enable the internal pull up resistors like @essejcds says.
Use
pinMode(pin, INPUT_PULLUP);
to enable the internal pullup. The pinMode function reference.

Hi @groundFungus & @essejcds,

Thanks a lot for your help on this topic.
Your solution worked!
Very grateful for your help on this! :blush:

Great to hear.