Apart from the diode part, which has been explained correctly, the circuit shown in post #1 has a design flaw and will not work correctly:
With a control voltage of 5 V the motor should be off. But with +5 V on the control input, transistor Q2's base is still negative with respect to the emitter (+12 V). Thus Q2 will be on. Base current will be ~I
b = (12 V -5 V -0.6 V)/1 kΩ = 6.4 mA.
With a current gain of e.g. 50 this will be good for up to ~ 300 mA drive current for the motor. SO the motor will be on, not off.
Solutions:
- Use a NPN transistor and switch GND, see e.g. here.
- Use a level shifter (see e.g. this example which is for 5 V but can easily be modified for 12 V).
- Use a 12 V control voltage.