HC-SR04 Ultrasonic Sonar sensor not working properly.

Hello good people,
I am trying to run a simple test with an Arduino Mega and a HC-SR04 sonar sensor. I have uploaded this code, so that the buzzer will notify if the distance is smaller than 90 cm.

int buzzerPin = 7;
int trigPin = 10;
int echoPin = 11;

void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(buzzerPin, OUTPUT);
}

void loop() {
  int duration, distance;
  digitalWrite (trigPin, HIGH);
  delayMicroseconds (10);
  digitalWrite (trigPin, LOW);
  distance = pulseIn (echoPin, HIGH);
  distance = distance/58;

      Serial.print(distance);   
      Serial.print("cm");
      Serial.println();

  if (distance < 90) {  
    digitalWrite (buzzerPin, HIGH);
  } else {
    digitalWrite (buzzerPin, LOW);
  }
}

But the problem is sometimes it buzzes when there’s nothing within 90 cm distance. I have checked my connections many times. All ok. But it is not working properly. Can any one help me to find out what’s wrong?
Thank You! <3

Sometimes there are random glitches. One simple way to deal with that problem is to use the median method of the NewPing library.

DaveEvans:
Sometimes there are random glitches. One simple way to deal with that problem is to use the median method of the NewPing library.

Okay, I am trying with the median method. Thanks for your suggestion!