How to drive the piezo buzzer?

Looks like the voltage and current are perfect for hooking the piezo directly up to one of 3.3V 20mA outputs of the Core. Since you are using the analogWrite(), you are stuck with 500Hz which is a pretty low frequency. Your piezo’s resonant frequency is 2300Hz, so will therefor be louder if you drive it at that frequency. It’s also easier to hear a 2 - 4kHz frequency.

You could try my Remote RTTTL library, but it might be overkill for a few beeps. However, it might be more FUN! xD

You’ll want a D7 note (2349Hz). Try this song:
char *song = (char *)"2.34kHzBeeps:d=4,o=7,b=240:d,p,d,p,d,p,d,p";

I just pushed a change to the code that fixed the octave selection, it was one lower than selected… at the same time I added your 2.34kHz beeps… tested and measured as 2.34kHz. Play with speeding up the beeps or slowing them down with the BPM (b=240) or default duration (d=4) or the notes themselves (d vs. 8d, vs 4d), or tweaking the pitch (c vs e vs a etc…)

You can even just strip out the tone() function and send it tone(D6, 213, 500); to play a D7 note on pin D6 for 500ms, then roll your own delays.

1 Like