ultrasonic contacless alcohol dispneser

i am building an ultrasonic based contactless alcohol dispenser, but the problem is that when input my code and check the distance through the serial monitor, the distance shown is always within the set limit for the pump to turn on(when there is a hand below it), but the arduino doesnt always work as programmed, sometimes it works sometimes it doesnt, im really having an issue right here, could you please help, my only issue is that i want this to be stand alone system, and efficient, cause mostly in the serial monitor i see value within the set limit, but the pump doesnt turn on, when i check using my multi tester, despite the distance being good enough to turn on the pump, there is no voltage coming out of that pin, i have tried using several pins on the board but never go the perfect system.

currently im using an
-original arduino uno
-HC-SR04 ultrsonic sensor
a powerbank
-5v dc pump
-data cable

any help would be appreciated

below is my code(if there is any problem please help me)

//CODE
#define echoPin 2 // attach pin D2 Arduino to pin Echo of HC-SR04
#define trigPin 3 //attach pin D3 Arduino to pin Trig of HC-SR04

// defines variables
long duration; // variable for the duration of sound wave travel
int distance; // variable for the distance measurement
const int watrPump = 4;

void setup() {
Serial.begin(9600);
pinMode(watrPump, OUTPUT);
pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT
pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT
Serial.begin(9600); // // Serial Communication is starting with 9600 of baudrate speed
Serial.println(“Ultrasonic Sensor HC-SR04 Test”); // print some text in Serial Monitor
Serial.println(“with Arduino UNO R3”);
}
void loop() {
// Clears the trigPin condition
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin HIGH (ACTIVE) for 10 microseconds
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; // Speed of sound wave divided by 2 (go and back)
// Displays the distance on the Serial Monitor
Serial.print(“Distance: “);
Serial.print(distance);
Serial.println(” cm”);

if(distance <=8)
{
digitalWrite(watrPump, HIGH);
delay(1000);

}
else
digitalWrite(watrPump, LOW);

}

i am building an ultrasonic based contactless alcohol dispenser, but the problem is that when input my code and check the distance through the serial monitor, the distance shown is always within the set limit for the pump to turn on(when there is a hand below it), but the arduino doesnt always work as programmed, sometimes it works sometimes it doesnt, im really having an issue right here, could you please help, my only issue is that i want this to be stand alone system, and efficient, cause mostly in the serial monitor i see value within the set limit, but the pump doesnt turn on, when i check using my multi tester, despite the distance being good enough to turn on the pump, there is no voltage coming out of that pin, i have tried using several pins on the board but never go the perfect system.

currently im using an
-original arduino uno
-HC-SR04 ultrsonic sensor
a powerbank
-5v dc pump
-data cable

any help would be appreciated

below is my code(if there is any problem please help me)

//CODE
#define echoPin 2 // attach pin D2 Arduino to pin Echo of HC-SR04
#define trigPin 3 //attach pin D3 Arduino to pin Trig of HC-SR04

// defines variables
long duration; // variable for the duration of sound wave travel
int distance; // variable for the distance measurement
const int watrPump = 4;

void setup() {
Serial.begin(9600);
pinMode(watrPump, OUTPUT);
pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT
pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT
Serial.begin(9600); // // Serial Communication is starting with 9600 of baudrate speed
Serial.println(“Ultrasonic Sensor HC-SR04 Test”); // print some text in Serial Monitor
Serial.println(“with Arduino UNO R3”);
}
void loop() {
// Clears the trigPin condition
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin HIGH (ACTIVE) for 10 microseconds
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; // Speed of sound wave divided by 2 (go and back)
// Displays the distance on the Serial Monitor
Serial.print(“Distance: “);
Serial.print(distance);
Serial.println(” cm”);

if(distance <=8)
{
digitalWrite(watrPump, HIGH);
delay(1000);

}
else
digitalWrite(watrPump, LOW);

}

Try putting a “delay(50)” as the last thing in loop()

And please remember to use code tags when posting code

It is preferable to use code tags to post sketches ( </> )

Could you take a few moments to Learn How To Use The Forum.
It will help you get the best out of the forum in the future.
Other general help and troubleshooting advice can be found here.

@ginchdol, do not cross-post. Threads merged.

i really appreciate your help, sorry about the code tags thingy, actually i tried adding the delay a the end, but it worked right only for the day, that night i disconnected it from power and when i connected it to power back it started malfunctioning

We can’t see your code