Go Down

Topic: "tick tock" sound from a piezoelectric speaker  (Read 4444 times) previous topic - next topic

keith726

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?

runaway_pancake

Admittedly, it's not a piezo speaker, but a relay can do a good tick-tock sound.
"Who is like unto the beast? who is able to make war with him?"
When all else fails, check your wiring!

Grumpy_Mike

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.

el_supremo

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
Don't send me technical questions via Private Message.

el_supremo

#4
Feb 09, 2015, 06:51 pm Last Edit: Feb 09, 2015, 06:52 pm by el_supremo
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
Don't send me technical questions via Private Message.

snorren

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!

Go Up