Ultrasonic sensor reading only zeros

Using this code to get a buzzer to go off when an ultrasonic sensor reads under a certain distance. It was working for a while but then it just started reading zeros, tried switching out the sensor with a couple different ones and the issue persisted. Is there something wrong with the code?

int trigPin = 9;
int echoPin = 10;
int buzzer = 7;

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

void loop() {
  long duration, distance;

  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);
  distance = (duration / 2) / 29.1;

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

  if (distance <= 10) {
    digitalWrite(buzzer, HIGH);
  } else {
    digitalWrite(buzzer, LOW);
  }

  delay(10);
}

Possibly, the buzzer is overloading the port pin, which can destroy the Arduino.

Please read the "How to get the best out of this forum" post and follow the instructions to provide the details.

Is it an HC-SR04? If so, I had ever got problems with them, 3 out of 4 were faulty, giving almost exactly the behaviour you described: they started returning 0 distance after a while no obstacle has been detected (aka: timeout). The only real solution was to power the sensor off and on to get it back working, but I found a workaround, doing this when I read pulseDuration equals to zero:

    if (pulseDuration == 0 ) {
      // SR04 unlock
      pinMode(EchoPin, OUTPUT);
      digitalWrite(EchoPin, LOW);
      delay(50);
      pinMode(EchoPin, INPUT);

But at the end I switched to the more reliable HY-SRF05: they cost a few cents more but I have never ever had problems with them!