Home

How to Sound a Tone

A piezoelectric buzzer like the Murata PKM22EPP is not designed for use as a general purpose audio speaker, as it is optimized for 2000 Hz or 4000 Hz tones. With 1 kilohm series resistor, it does work acceptably for testing Arduino audio tone services.

void setup()
{
  pinMode(2, OUTPUT);

  // Sound a 300 millisecond beep in the foreground
  tone(2, 1000);
  delay(300);
  noTone(2);

  delay(1000);

  // Sound a 300 millisecond beep in the background
  tone(2, 1000, 300);
  
  delay(1000);

  tone(2, 400, 1000); // Low tone will be replaced immediately
  tone(2, 2000, 300); // High tone replaces low tone
}

Home


Questions or comments to phil@munts.net