I am having a little trouble with the piezo speaker. I connected it to digital pin 5 (because it has PWM) and GND - no resistors or anything. When I do analogWrite, I can hear the melody that I want but I have to have my ear realy close to the speaker. I am using very similar piezo (both are from computer motherboards) in one of my other projects and it is quite loud. But for some reason this one is not. I also tryed a normal "system speaker" - not piezo. I connected it via 100 ohm resistor - nothing. But without the resistor I can get some sound but again you can't realy hear it if you are not close to the speaker.
EDIT: tryed it on pin 11 - and for some reason here the whole thing plays a melody loud enough. Tryed another pin without PWM and it plays melody too. So why is it so quiet with pin 5 on two different boards?
I would guess because square waves in the audio spectrum are a good way to drive a piezo element! PWM outputs are about 500 and 1000 Hz depending on which timer the pin uses.
My guesss for the volume switching pins solution is that pin 11 does not have PWM, so it essentially does digitalWrite() instead of analogWrite(). IDK though.