Use HC-SR04 Ultrasonic Sensor to move a motor

I'm puzzled by the lack of debug prints in your code.
Why not add some, and use the output to tell you what is going on - debugging with stepper motors isn't easy.