Arduino Forum

Using Arduino => Audio => Topic started by: keith726 on Feb 09, 2015, 02:01 am

Title: "tick tock" sound from a piezoelectric speaker
Post by: keith726 on Feb 09, 2015, 02:01 am
I am building a clock and I want to make "tick tock" sounds
using a piezoelectric speaker.
What is the code to produce these sounds?
Title: Re: "tick tock" sound from a piezoelectric speaker
Post by: runaway_pancake on Feb 09, 2015, 03:04 am
Admittedly, it's not a piezo speaker, but a relay can do a good tick-tock sound.
Title: Re: "tick tock" sound from a piezoelectric speaker
Post by: Grumpy_Mike on Feb 09, 2015, 08:57 am
You do not get very good quality noises from a piezoelectric speaker even if you have a good quality waveform to give it.
The simplest way would to get a wave shield and play the sounds from that.
Title: Re: "tick tock" sound from a piezoelectric speaker
Post by: el_supremo on Feb 09, 2015, 06:48 pm
Radio station WWV uses a 5 ms long pulse of 1000 Hz (i.e. 5 cycles) to make the sound of a "tick". I tested it with an 8ohm speaker (with 150 ohm resistor in series) and this code:
Code: [Select]

// Change this to the output pin you are using
#define TICK_PIN 17

void setup()
{
  pinMode(TICK_PIN,OUTPUT);
  for(int i = 0;i < 5;i++) {
    tone(TICK_PIN,1000,5);
    delay(1000);
  }
}
 
void loop()
{
}


Sounds pretty good, although 3ms sounds better on the speaker I am using.

Pete
Title: Re: "tick tock" sound from a piezoelectric speaker
Post by: el_supremo on Feb 09, 2015, 06:51 pm
P.S. for a tick-tock sound try this in the for loop:
Code: [Select]

    tone(TICK_PIN,1000,5);
    delay(1000);
    tone(TICK_PIN,500,5);
    delay(1000);


Pete
Title: Re: "tick tock" sound from a piezoelectric speaker
Post by: snorren on Jul 25, 2018, 07:37 am
Late for the party but just wanted to thank you for the two sounds, fits my piezo buzzers perfect and will be terrific feedback sounds in my menu system!