Turn Off Buzzer when current isnt flowing

Basically im doing a battery tester that produces a pitch and turns on a LED when certain voltage is passing through the system. My problem is that the buzzer keeps making noise

// Pines para los LEDs
#define LEDVERDE 2
#define LEDAMARILLO 3
#define LEDROJO 4
#define ANALOGPILA 0
// Variables
const int pinBuzzer = A1;
int analogValor = 0;
float voltaje = 0;
int ledDelay = 800;
// Umbrales
float maximo = 1.46;
float medio = 0.9;
float minimo = 0.3;
void setup() {
// Iniciamos el monitor serie
Serial.begin(9600);
// Los pines de LED en modo salida
pinMode(LEDVERDE, OUTPUT);
pinMode(LEDAMARILLO, OUTPUT);
pinMode(LEDROJO, OUTPUT);
}
void loop() {
// Leemos valor de la entrada analógica
analogValor = analogRead(ANALOGPILA);
// Obtenemos el voltaje
voltaje = 0.0048 * analogValor;
Serial.print("Voltaje: ");
Serial.println(voltaje);
// Dependiendo del voltaje mostramos un LED u otro
if (voltaje >= maximo)
{
digitalWrite(LEDGREEN, HIGH);
delay(ledDelay);
digitalWrite(LEDGREEN, LOW);
tone(pinBuzzer, 500);
delay(1000);
}
else if (voltaje < maximo && voltaje > medio)
{
digitalWrite(LEDYELLOW, HIGH);
delay(ledDelay);
digitalWrite(LEDYELLOW, LOW);
tone(pinBuzzer, 340);
delay(1000);
}
else if (voltaje < medio && voltaje > minimo)
{
digitalWrite(LEDRED, HIGH);
delay(ledDelay);
digitalWrite(LEDRED, LOW);
tone(pinBuzzer, 180);
}
// Turn off LEDs
digitalWrite(LEDGREEN, LOW);
digitalWrite(LEDYELLOW, LOW);
digitalWrite(LEDRED, LOW);

}

My problem is that the buzzer keeps making noise

You need to specify a duration for the tone or turn it off by usung noTone()

See tone()

The thing is that if i do that then the buzzer wont sound

chavodel8: The thing is that if i do that then the buzzer wont sound

When specifying a duration, or when using noTone()?

Well after a lot of research I solved my problem

chavodel8: Well after a lot of research I solved my problem

Please share your solution with us.