pausing and continuing a stepper motor. PLEASE HELP!!!

Hi, I am new to Arduino and not the best programmer. I am working on a project and need help fixing my code. My plan is to have a stepper motor to turn clockwise(180 degrees) to pull the trigger on a pressure washer spray gun. When the ultra sonic sensor detects an object within its set distance, it will trigger the motor again to turn counterclockwise and release the trigger causing the water to stop. The spray gun should remain off until the object is out of the way and the sensors cannot detect anything in its path to where it would spin clockwise again and pull the trigger.

Thank you.

#include <Stepper.h>

// defines pins numbers
const int stepsPerRevolution = 100;
const int trigPin = 23;
const int echoPin = 22;
Stepper StepperMotor(stepsPerRevolution, 46, 48, 50, 52);



// defines variables
long duration;
int distance;

void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
StepperMotor.setSpeed(100);

Serial.begin(9600); // Starts the serial communication
}

void stopmotor(){
  StepperMotor.setSpeed(0);
}
void clockwise(){
  Serial.println("clockwise");
  StepperMotor.step(stepsPerRevolution);
}

void counterclockwise(){
  Serial.println("counterclockwise");
  StepperMotor.step(-stepsPerRevolution);
}
void loop() {
  
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);


// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);


// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);


// Calculating the distance
distance= duration*0.034/2;


// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);


if (distance > 5){
clockwise();
delay(500);

}

if (distance <= 10){
counterclockwise();
delay(500);

}

 
}

What does the code actually do that is not right?

You might consider using a servo for this purpose since you can set the exact angle you want.

Otherwise, what problem are you having?