Using an ultrasonic sensor to control motor to move in the forward and reverse direction

The motor rotates in the forward direction then pauses for a sec and keeps on rotating and vice versa when i bring a wall near the ultrasonic sensor you get?
What i want is for it to rotate for a sec then stop and vice versa when i bring a wall near the ultrasonic sensor