As you can see in the file, when we hold the button, the motor will move clockwise due to the right relay, and then counterclockwise due to the left relay.
To build the circuit, I used:
-
Arduino board.
-
DC motor.
-
Button for the DC motor.
-
Two relays (instead of L298 motor driver).
-
Two 2N2222 transistors for the relays.