How to design mechanical switches to an arduino controlled circuit
So you want the limit switches to be a hardware interlock to the motor.

You can use a logic gates to force the inputs of the motor driver to remain off should the arduino try to move beyond the limits.

For example if the close limit switch is pressed it then forces the output the driver sees coming from pin9 to be LOW regardless what the arduino tries to do. But it still allows the other pin to be pulled high so the motor can reverse.







simulate this circuit &ndash; Schematic created using CircuitLab

Repeat for the other pin.

You can still connect the switch to the arduino to read the switch state. In this configuration a HIGH signal means the switch is not hit and a LOW signal means the limit switch is hit.