EmbeddedRelated.com
Forums
The 2026 Embedded Online Conference

PWM sound effect for embedded MCU

Started by Unknown May 23, 2016
I need to generate sounds using a piezoelectric buzzer for my embedded MCU.

Anybody know of some form of sound library on the net that has different sound effects using PWM?

I need to generate button press sounds and some kind of alarm sounds. Reply correct input with some kind of happy sound and error input with a sad sound :-)

On 23.5.16 21:13, karlskogasweden@gmail.com wrote:
> I need to generate sounds using a piezoelectric buzzer for my embedded MCU. > > Anybody know of some form of sound library on the net that has different sound effects using PWM? > > I need to generate button press sounds and some kind of alarm sounds. Reply correct input with some kind of happy sound and error input with a sad sound :-)
A piezoelectric buzzer is ill suited to reproducing sounds of many kinds, due to its narrow resonance band. The situation does not change by feeding badly suitable PWM to it. About the only way to produce messages with it is some kind of Morse code. -- -TV
On 5/23/2016 11:20 AM, Tauno Voipio wrote:
> On 23.5.16 21:13, karlskogasweden@gmail.com wrote: >> I need to generate sounds using a piezoelectric buzzer for my embedded >> MCU. >> >> Anybody know of some form of sound library on the net that has >> different sound effects using PWM? >> >> I need to generate button press sounds and some kind of alarm sounds. >> Reply correct input with some kind of happy sound and error input with >> a sad sound :-) > > A piezoelectric buzzer is ill suited to reproducing sounds of many > kinds, due to its narrow resonance band. The situation does not change > by feeding badly suitable PWM to it. > > About the only way to produce messages with it is some kind of Morse code.
I agree with your response but I wonder if it might be possible to craft a heavily modified (or not) source audio file (like a voice command) that will sound acceptable on a piezo buzzer. JJS
On 23.5.16 21:34, John Speth wrote:
> On 5/23/2016 11:20 AM, Tauno Voipio wrote: >> On 23.5.16 21:13, karlskogasweden@gmail.com wrote: >>> I need to generate sounds using a piezoelectric buzzer for my embedded >>> MCU. >>> >>> Anybody know of some form of sound library on the net that has >>> different sound effects using PWM? >>> >>> I need to generate button press sounds and some kind of alarm sounds. >>> Reply correct input with some kind of happy sound and error input with >>> a sad sound :-) >> >> A piezoelectric buzzer is ill suited to reproducing sounds of many >> kinds, due to its narrow resonance band. The situation does not change >> by feeding badly suitable PWM to it. >> >> About the only way to produce messages with it is some kind of Morse >> code. > > I agree with your response but I wonder if it might be possible to craft > a heavily modified (or not) source audio file (like a voice command) > that will sound acceptable on a piezo buzzer.
Any sound that could be produced will sound very tinny with the characteristic frequency of the element overwhelming. In addition, the high Q of the buzzer element makes all sounds start and end slowly. -- -TV
On 5/23/2016 11:13 AM, karlskogasweden@gmail.com wrote:
> I need to generate sounds using a piezoelectric buzzer for my embedded MCU.
Do you have a choice in the transducer being used? I.e., MUST it be a piezo? (You'd have more flexibility with a small speaker)
> Anybody know of some form of sound library on the net that has different > sound effects using PWM? > > I need to generate button press sounds and some kind of alarm sounds. Reply > correct input with some kind of happy sound and error input with a sad sound > :-)
I think you're going to end up with beeps (at the piezo's fundamental frequency) of various cadences: beeeeeeeeep! beep beep beep beep beep beeeeeeep etc. A piezo is really only good at "getting attention", not conveying information.
Tauno Voipio <tauno.voipio@notused.fi.invalid> writes:
>> Reply correct input with some kind of happy sound and error >> input with a sad sound :-) > A piezoelectric buzzer is ill suited to reproducing sounds of many > kinds, due to its narrow resonance band.
I think it's doable. A rising tone for happy and a falling tone for sad.
On 23/05/2016 19:20, Tauno Voipio wrote:
> On 23.5.16 21:13, karlskogasweden@gmail.com wrote: >> I need to generate sounds using a piezoelectric buzzer for my embedded >> MCU. >> >> Anybody know of some form of sound library on the net that has >> different sound effects using PWM? >> >> I need to generate button press sounds and some kind of alarm sounds. >> Reply correct input with some kind of happy sound and error input with >> a sad sound :-) > > A piezoelectric buzzer is ill suited to reproducing sounds of many > kinds, due to its narrow resonance band. The situation does not change > by feeding badly suitable PWM to it. > > About the only way to produce messages with it is some kind of Morse code.
There was an ancient DOS golf game which used the PC piezo sounder to generate speech commentary and other sounds using PWM. It was tinny, but perfectly understandable. Cheers -- Syd
On 24.5.16 14:35, Syd Rumpo wrote:
> On 23/05/2016 19:20, Tauno Voipio wrote: >> On 23.5.16 21:13, karlskogasweden@gmail.com wrote: >>> I need to generate sounds using a piezoelectric buzzer for my embedded >>> MCU. >>> >>> Anybody know of some form of sound library on the net that has >>> different sound effects using PWM? >>> >>> I need to generate button press sounds and some kind of alarm sounds. >>> Reply correct input with some kind of happy sound and error input with >>> a sad sound :-) >> >> A piezoelectric buzzer is ill suited to reproducing sounds of many >> kinds, due to its narrow resonance band. The situation does not change >> by feeding badly suitable PWM to it. >> >> About the only way to produce messages with it is some kind of Morse >> code. > > There was an ancient DOS golf game which used the PC piezo sounder to > generate speech commentary and other sounds using PWM. It was tinny, > but perfectly understandable.
The PC sounder was not a piezo, but a small speaker connected to the timer chip output. You can produce rough but understandable sound from a speaker with single bit feed by feeding it with fast enough PWM or sigma-delta. -- -TV
On 24/05/2016 15:25, Tauno Voipio wrote:

<snip>
> > The PC sounder was not a piezo, but a small speaker connected to the > timer chip output.
You're right, I stand corrected. Cheers -- Syd
The 2026 Embedded Online Conference