Going Both Ways

Why wouldn't the motor always be connected?
If I am understanding you, an opto isolator might work.

.