Build the circuit shown in the diagram.
The black item is the piezo or speaker.
The small grey/blue item with 3 pins is the potentiometer.
It doesn't matter which side the black and red wires connect to on the potentiometer as long as yellow to pin A0 is in the centre.
The code below will cause this circuit to play a constant low sound when the potentiometer reads 400 or less, a constant high-pitched sound when it reads 800 or greater, and a varying pitch for all values between.
The code also provides for an LED to be connected to pin 13 which will turn on when the value read from the pot pin is between 400 and 800.