Specifications

Chapter 6 - Samples
Previous page Table of contents Chapter overview Next page
Generating a sound
A Piezo diaphragm can be added to an output line of a microcontroller to deliver a "speaker"
tones, beeps and signals.
It is important to know there are two main types of piezo sound-emitting devices. One has active
components inside the case and only requires a DC supply for the "speaker" to emit a tone or
beep. Generally the tones or beeps emitted by these "speaker" or "beepers" cannot be changed -
they are fixed by the internal circuitry. This is not the type we are discussing in this article.
The other type consists of a piezo diaphragm and requires a signal to be delivered to it for it to
function. Depending on the frequency of the waveform, the output can be a tone, tune, alarm or
even voice messages.
In order for them to work we must deliver a cycle consisting of a HIGH and LOW. It is the change
from HIGH to LOW or LOW to HIGH that causes the diaphragm to "dish" (move) to produce the
characteristic "tinny" sound. The waveform can be a smooth change from one value to the other
(called a sinewave) or a fast change (called a SQUARE WAVE). A computer is ideal for producing a
square wave. The square wave delivery produces a slightly harsher output.
Connecting a piezo diaphragm is very simple. One pin is connected to the negative rail and the
other to an output of a microcontroller, as shown in the diagram below. This will deliver a 5v
waveform to the piezo diaphragm. To produce a higher output, the waveform must be increased
and this requires a driver transistor and inductor.
Connecting a piezo diaphragm to a microcontroller
As with a key, you can employ a macro that will deliver a BEEP ROUTINE into a program when
needed.
BEEP macro freq , duration:
freq: frequency of the sound. The higher number produces higher frequency
http://www.mikroelektronika.co.yu/english/product/books/PICbook/6_07Poglavlje.htm (1 of 4) [4/2/2003 16:18:57]