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?
Admittedly, it's not a piezo speaker, but a relay can do a good tick-tock sound.
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.
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:
// 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
P.S. for a tick-tock sound try this in the for loop:
tone(TICK_PIN,1000,5);
delay(1000);
tone(TICK_PIN,500,5);
delay(1000);
Pete
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!