problem with buzzer, piezo not stop buzzing without any action

i’m noobies here need some help from you guys

this is my code

// These constants won't change.  They're used to give names
// to the pins used:
const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
const int ledPin = 13;                 // LED connected to digital pin 13
int pinSpeaker = 10;           //Set up a speaker on a PWM pin (digital 9, 10, or 11)
int sensorValue = 0;        // value read from the sensor




void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600); 
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
  pinMode(pinSpeaker, OUTPUT);
}

void loop() {
  // read the analog in value:
  sensorValue = analogRead(analogInPin);            
  // determine alarm status
  if (sensorValue >= 750)
  {
    digitalWrite(ledPin, HIGH);   // sets the LED on
    playTone(300, 260);
  }
  else
  {
  digitalWrite(ledPin, LOW);    // sets the LED off
  playTone(0, 0);
  }

  // print the results to the serial monitor:
  Serial.print("sensor = " );                       
  Serial.println(sensorValue);     

  // wait 10 milliseconds before the next loop
  // for the analog-to-digital converter to settle
  // after the last reading:
  delay(0);                     
}
void playTone(long duration, int freq) {
    duration *= 1000;
    int period = (1.0 / freq) * 1000000;
    long elapsed_time = 0;
    while (elapsed_time < duration) {
        digitalWrite(pinSpeaker,HIGH);
        delayMicroseconds(period / 2);
        digitalWrite(pinSpeaker, LOW);
        delayMicroseconds(period / 2);
        elapsed_time += (period);
    }
}

my coding is working. i’m use Smoke Sensor + LED + PIEZO BUZZER for this little project but im stress with the buzzer that always buzzing. how to stop that buzzing… thanks for pay attention… thank you very much for helping…

Is it impossible to use Tone and NoTone for this purpose ?

tq for reply my question, :) it impossible because I already try it before this, its keep buzzing.. :~ and im not pure programmer.. :cold_sweat:

U use the buzzer as a apeake...

replace this line : playTone(0, 0); with digitalWrite(pinSpeaker,LOW);