DC motors are often used in electronic projects and a special case is when a DC motor needs to be brought to a certain begin or end position without going further. Typically limit switches are then used. Such a switch is pressed by the motor when that motor reaches its end position. Similarly such a switch can be used when a motor reaches its begin position again.
Obviously, when a limit switch is pressed an action needs to be taken to stop the motor. The solution for that is in fact simple and old news, but surprisingly many hobbyists don’t know about that solution or struggle with it, and that’s why I will explain it here (with apologies to all people who do know it)
In the picture above there is a typical circuit for a motor with limit switches. Let’s presume the left switch is opened when the motor comes to its desired left position and the right one opens when the motor comes to its desired right position. Let’s also presume that the motor in that picture is in between left and right position.
It is easy to see that the electrical circuit is closed and that it doesn matter what polarity is used.
We then apply a positive voltage to the top wire and a negative voltage to the bottom wire. The motor starts turning left, until it reaches, presses and opens SW1.
At that moment, the electric circuit is open: Switch S1 is open and the left diode blocks a positive voltage. The motor stops.
To make the motor go back to its original position, we need to reverse polarity, so now the left most diode sees a negative voltage on its cathode and wil conduct curent: the motor turns reverse. After it travelled a fraction, SW1 will close again (as in the firts picture)…but that only becomes relevant later. We let the motor travel reverse till it comes to its desired right position, where it opens SW2.
As soon as SW2 is open, the circuit gets broken again, no current will flow and the motor stops. As SW1 has closed again after the motor started travelling, the circuit will now conduct for a positive voltage on the top connector. Though SW2 is open, the right-side diode will conduct.