This sensor is a piezo element. It can be used as either a speaker or to detect vibrations like knocking. Here we are using it to detect knocking. Whenever we spot a transition, we delay for 20ms to make sure it is a knock and not left over vibrations from an earlier knock. You can experiment with this value.