Use HC-SR04 Ultrasonic Sensor to move a motor

In your first post on this thread, you had some Serial.print in your function "dist()".
If you know the values "dist" is returning, you can have a better idea how your sketch is performing.