How to make a DC motor act as some sort of switch

Use a relay as a switch instead of a rotating motor