TIMING A BUZZER SOUND & TURNING OFF

So I have a university project due in a few days and we want the servo to be in the 0 degree position and make a tune for example, 5 secs then using a potentiometer we twist to a 1023 position (180 degrees) and it plays a different tune and then stops. The problem is stopping the buzzer after a certain time period,
We also want the sounds to only come on at these specific points.
PLEASE HELP! :slight_smile:

This is our code.

#include <Servo.h> // add servo library

Servo myservo; // create servo object to control a servo

int potpin = A0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
int piezo= 8;

void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode (potpin, INPUT);
pinMode (piezo, OUTPUT);
Serial.begin (9600);

}

void loop() {

val = analogRead(potpin);
Serial.println (val);// reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there

if (val==0)
{
tone (piezo, 1000,500);

delay(1000);
noTone(piezo);
delay (50);

}

else if (piezo, 0);{
//analogWrite (piezo, 0);
}

if (val==1023)
{
tone (piezo, 3000,500);

delay (200);
}

else if( piezo, 0);{

//analogWrite (piezo, 0);
}
}

  else if ( piezo, 0);

Wrong syntax for an if and the semicolon should not be there in any case

no code tags, hardly any indent and irregular, apparently the future of the nation (students ay !?) post the code in tags and i'll have a look. ah and not so many empty lines please, an empty line should mean something, within a few days it i'll be sorted.