There are 4/5 nice sketches bundled with Arduino IDE as examples: -> Digital : tone* -> Sensors: knock