SOUND INPUT AND OUTPUT
The robots of science fiction are seldom mute or deaf. They may speak pithy warnings—the most famous probably being: “Danger, Danger, Will Robinson”—or squeak out blips
and beeps in some “advanced” language only other robots can understand. Voice and sound
input and output make a robot more humanlike, or at least more entertaining. What is a
personal robot for if not to entertain?
What’s good for robots in novels and in the movies is good enough for us, so this chapter
presents a number of useful projects for giving your mechanical creations the ability to
make and hear noise. The projects include using recorded sound, generating warning
sirens, recognizing and responding to your voice commands, and listening for sound events.
Admittedly, this chapter only scratches the surface of what’s possible today, especially with
technologies like MP3 compressed digitized sound.
31.1 Cassette Recorder Sound Output
Before electronic doodads took over robotics there were mechanical solutions for just
about everything. While they may not always have been as small as an electrical circuit,
they were often easier to use. Case in point: you can use an ordinary cassette tape and
playback mechanism to produce music, voice, or sound effects. Tape players and tape
player mechanisms are common finds in the surplus market, and you can often find complete
(and still working) portable cassette players-recorders at thrift stores. With just a few wires you can rig a cassette tape player in the robot and have the sound played back, on your command.
When looking for a cassette player try to find the kind shown in Fig. 31-1, which is solenoid
controlled. These are handy for your robot designs because instead of pressing
mechanical buttons, you can actuate solenoids by remote or computer control to play, fast-forward,
or rewind the tape. They can be somewhat difficult to find as they are usually built
into more expensive soft-touch tape decks and are not readily found in surplus bins.
For most cassette decks you only need to provide power to operate the motor(s) and
solenoids (if any) and a connection from the playback head to an amplifier. Since you are
not using the deck for recording, you don’t have to worry about the erase head or biasing the record head. If the deck already has a small preamplifier for the playback head, use it.
It’ll improve the sound quality. If not, you can use the tape head preamplifier shown in
Fig. 31-2 (you can use a less expensive op amp than the one specified in the parts list in
tag. 31-1, but noise can be a problem). Place the preamplifier board as close to the cassette
deck as possible to minimize stray pickup.
TABLE 31-1 Parts List for Cassette Tape Head Player Amplifier |
IC1 |
LT1007 low-noise operational amplifier (Linear Technology) |
R1 |
330K resistor |
R2 |
4.9K resistor |
R3 |
100-Ω resistor |
C1 |
0.1 μF ceramic capacitor |
|
31.2 Electronically Recorded Sound Output
While mechanical sound playback systems like the cassette recorder are adequate, they lack
the response and flexibility of a truly electronic approach. Fortunately, all-electronic reproduction
of sound is fairly simple and inexpensive, in large part because of the wide availability
of custom-integrated circuits that are designed to record, store, and play back
recorded sound. Most of these chips are made for commercial products such as microwave
ovens, cellular phones, or car alarms.
31.2.1 HACKING A TOY SOUND RECORDER
You can hack toy sound recorders, such as the Yak Bak, for use in your robot. These
units, which can often be found at toy stores for under $10, contain a digital sound-recording
chip, microphone, amplifier, and speaker (and sometimes sound effects generator).
To use them, you press the Record button and speak into the microphone. Then,
stop recording and press the play button and the sound will play back until you make a
new recording.
Fig. 31-3 shows a Yak Bak toy that was disassembled and hacked by soldering wires
directly to the circuit board. The wires, which connect to a microcontroller or computer, are
in lieu of pressing buttons on the toy to record and play back sounds. The buttons on most
of these sound recorder toys are made of conductive rubber and are easily removed. To
operate the unit via a microcontroller or computer, you bring the button inputs HIGH or
LOW. (Which value you choose depends on the design of the circuit; you need to experiment to find out which to use.) Connect a 1K to 3K resistor between the I/O pin and the
button input.
Suppose you have a Yak Bak or similar toy connected to I/O pin 1 on a Basic Stamp 2. Assume that on the toy you are using, bringing the button input HIGH triggers a previously recorded sound snip. The control program is as simple as this:
high1
pause10
low1
The program starts by bringing the button input (the input of the toy connected to pin 1 of the BASIC Stamp) HIGH. The pause statement waits 10 ms and then places the button LOW again.
The built-in amplifier of these sound recorder/playback toys isn’t very powerful. You may wish to connect the output of the toy to one of the audio output amplifiers described later in the chapter (see “Audio Amplifiers”).
31.2.2 USING THE ISD FAMILY OF VOICE-SOUND RECORDERS
Toy sound recorders are limited to playing only a single sample. For truly creative robot yapping,
you need a sound chip in which you can control the playback of any of several prerecorded
snips. You can do this easily by using the family of sound storage and playback chips produced by Information Storage Devices (ISD). The company has made these ChipCorder ICs readily available to the electronics hobbyist and amateur robot builder.
You can purchase ISD sound recorder chips from a variety of sources, including Jameco
and Digikey (see Appendix B). Prices for these chips vary depending on feature and recording
time, but most cost under $10. While there are certainly other makers of sound storage/
playback integrated circuits, the ISD chips are by far the most widely used and among the
most affordable.
Adding a BS2 to a robot is a fairly simple operation, although it can be difficult to work
through using just the data sheets. Using the circuit in Fig. 31-4 (with the parts listed in
Table 31-2), you can create your own BS2 to an ISD chip interface circuit using BS2
ICD.bs2 (in the following). When wiring the circuit, make sure you use a reasonably large
breadboard and that you leave lots of space between the chips and the end of the breadboard
for the various resistors and capacitors.
TABLE 31-2 Parts List for BS2 Control of an ISD Sound Recorder/Player Chip |
BS2 |
Parallax BASIC Stamp 2 |
IC1 |
ISD2532 sound recorder/player |
R1 |
330k resistor |
R2 |
4.7k resistor |
R3, R4 |
10k resistor |
R5 |
1k resistor |
C1 |
220 μF electrolytic capacitor |
C2, C3 |
0.1 μF electrolytic capacitor |
C4 |
10 μF electrolytic capacitor |
C5–C7 |
0.1 μF ceramic capacitor |
C8 |
220 μF electrolytic capacitor |
SW1 |
Breadboard mountable SPDT switch |
MIC |
Electret microphone |
SPKR |
16 Ω speaker |
Misc. |
Large breadboard (6 in or longer), breadboard wiring, 4× AA battery
clip, 4× AA alkaline batteries, BS2 serial port programmer interface |
|
This program uses the console interface presented earlier in the book for the BS2 I/O
port read and write accessing to demonstrate how this function can be used for different
applications. In a robot application, just the code that is used to Specify Record and Specify
Play is required.
This application runs the ISD chip in push-button control mode, which allows multiple
messages to be stored on the ISD chip, using address pins A0 through A5. This will give
you up to 32 (short) messages that can be used to show off the capabilities of the robot or
give you feedback as to what its input is or what functions it is executing.
31.3 Sirens and Other Warning Sounds
If you use your robot as a security device or to detect intruders, fire, water, or whatever,
then you probably want the machine to warn you of immediate or impending danger. The
warbling siren shown in Fig. 31-5 will do the trick, assuming it’s connected to a strong
enough amplifier (refer to the parts list in Table 31-3). The circuit is constructed using two
555 timer chips (alternatively, you can combine the functions into the 556 dual timer chip).
To change the speed and pitch of the siren, alter the values or R1 and R4, respectively.
TABLE 31-3 Parts List for Siren |
IC1, IC2 |
555 timer IC |
R1 |
10K resistor |
R2 |
1 MΩ |
R3 |
10K resistor |
R4 |
1K resistor |
R5 |
4.7K resistor |
C1 |
0.22 μF ceramic capacitor |
C2 |
0.1 μF ceramic capacitor |
|
For maximum effectiveness, connect the output of the IC2 to a high-powered amplifier.
You can get audio amplifiers with wattages of 8, 16, and more in easy-to-build kit form. See Appendix B, “Sources,” for a list of mail-order companies that also sell electronic
kits.
Unless you have all of the sound-making circuits in your robot hooked up to separate
amplifiers and speakers (not a good idea), you’ll need a way to select between the sounds.
The circuit in Fig. 31-6 uses a 4051 CMOS analog switch and lets you choose from
among eight different analog signal sources. You select input by providing a three-bit
binary word to the select lines. You can load the selection via computer or set it manually
with a switch. A binary-coded-decimal (BCD) thumbwheel switch is a good choice, or you
can use a four-bank DIP switch. Table 31-4 is the truth table for selecting any of the eight
inputs.
TABLE 31-4 4051 Truth Table
You can route just about any of your sound projects through this chip, just as long as the
outlet level doesn’t exceed a few milliwatts. Do not pass amplified sound through the chip.
Besides in all likelihood destroying the chip, it’ll cause excessive cross-talk between the
channels. It’s also important that each input signal not have a voltage swing that exceeds
the supply voltage to the 4051.
Fig. 31-7 (parts list in Table 31-5) shows a rather straightforward 0.5-W sound amplifier
that uses the LM386 integrated amplifier. The sound output is minimal, but the chip is easy
to get, cheap, and can be wired up quickly. It’s perfect for experimenting with sound projects.
The amplifier as shown has a gain of approximately 20, using minimal parts. You can
increase the gain to about 200 by making a few wiring changes, as shown in Fig. 31-8
(parts list in Table 31-6). Either amplifier will drive a small (2- or 3-in) 8-Ω speaker.
TABLE 31-5 Parts List for GAIN-200 Audio Amplifier |
IC1 |
LM386 audio amplifier IC |
R1 |
10 Ω resistor |
R2 |
10K potentiometer |
C1 |
0.047 μF ceramic capacitor |
C2 |
250 μF electrolytic capacitor |
SPKR1 |
8-Ω miniature speaker |
|
TABLE 31-6 Parts List for GAIN-200 Audio Amplifier |
IC1 |
LM386 audio amplifier IC |
R1 |
10 Ω resistor |
R2 |
10K potentiometer |
C1 |
100 μF electrolytic capacitor |
C2 |
0.047 μF ceramic capacitor |
C3 |
10 μF electrolytic capacitor |
C4 |
250 μF electrolytic capacitor |
SPKR1 |
8-Ω miniature speaker |
|
Robots that listen to your voice commands and obey? The technology is not only available,
it’s relatively inexpensive. Several companies, such as Sensory Inc. and Images Company,
offer full-featured speech recognition systems for under $100. Both require you to train the
system to recognize your voice patterns. Once trained, you simply repeat the command,
and the system sets one or more of its outputs accordingly.
The Voice Direct, from Sensory Inc., is relatively easy to set up and use. The unit consists
of a small double-sided circuit board that is ready to be connected to a microphone,
speaker (for auditory confirmation), battery, and either relays or a microcontroller. The
Voice Direct board recognizes up to 15 words or phrases and is said to have a 99 percent
or better recognition accuracy. Phrases of up to 3.2 s can be stored, so you can tell your
robot to "come here" or "stop, don't do that!" Fig. 31-9 shows a Voice Direct module; the
product comes with complete circuit and connection diagrams.
Keep the following in mind when using a voice recognition system:
- You must be reasonably close to the microphone for the system to accurately understand
your commands. The better the quality of the microphone you have, the better the accuracy
of the speech recognition.
- If you are using a voice recognition system on a mobile robot, you may wish to extend
the microphone away from the robot so motor noise is reduced. For best results, you’ll
need to be fairly close to the robot and speak directly and clearly into the microphone.
- Consider using a good-quality RF or infrared wireless microphone for your voice recognition
system. The receiver of the wireless microphone is attached to your robot; you
hold the microphone itself in your hand.
Not long ago, integrated circuits for the reproduction of human-sounding speech were fairly
common. Several companies, including National Semiconductor, Votrax, Texas Instruments,
and General Instrument, offered ICs that were not only fairly easy to use, even on the hobbyist
level, but surprisingly inexpensive. Voice-driven products using these chips included the
Speak-and-Spell toys and voice synthesizers for the blind. In most cases, these ICs could create
unlimited speech because they reproduced the fundamental sounds of speech (called
phonemes). With the proliferation of digitized recorded speech (using chips like the ISD chip
presented previously), unlimited speech synthesizers have become an exception instead of the
rule. The companies that made stand-alone speech synthesizer chips either stopped manufacturing
them or were themselves sold to other firms that no longer carry the old speech parts.
In addition, products such as the sound card for the IBM PC-compatible computers obviated
the need for a separate, stand-alone speech circuit. Using only software and a sound
card, it is possible to reproduce a male or female voice. In fact, Microsoft provides free
speech-making tools and operating system APIs for Windows. If you are using a robot controlled
by a laptop running Windows, adding synthesized speech is remarkably easy. See the
Microsoft site (www.microsoft.com) for more information.
Next to sight, the most important human sense is hearing. And compared to sight, sound
detection is far easier to implement in robots. You can build simple “ears” in less than an
hour that let your robot listen to the world around it.
Sound detection allows your robot creation to respond to your commands, whether they
take the form of a series of tones, an ultrasonic whistle, or a hand clap. It can also listen for
the tell-tale sounds of intruders or search out the sounds in the room to look for and follow
its master. The remainder of this chapter presents several ways to detect sound. Once
detected, the sound can trigger a motor to motivate, a light to go lit, a buzzer to buzz, or a
computer to compute.
Obviously, your robot needs a microphone (or mike) to pick up the sounds around it. The
most sensitive type of microphone is the electret condenser, which is used in most higher quality hi-fi mikes. The trouble with electret condenser elements, unlike crystal element mike,
is that they need electricity to operate. Supplying electricity to the microphone element really
isn’t a problem, however, because the voltage level is low—under 4 or 5 V.
Most electret condenser microphone elements come with a built-in field effect transistor
(FET) amplifier stage. As a result, the sound is amplified before it is passed on to the main
amplifier. Electret condenser elements are available from a number of sources, including
Radio Shack, for under $3 or $4. You should buy the best one you can. A cheap microphone
isn’t sensitive enough.
The placement of the microphone is important. You should mount the mike element
at a location on the robot where vibration from motors is minimal. Otherwise, the robot
will do nothing but listen to itself. Depending on the application, such as listening for
intruders, you might never be able to place the microphone far enough away from sound
sources or make your robot quiet enough. You’ll have to program the machine to stop and
then listen.
31.8.2 AMPLIFIER INPUT STAGE
The circuit in Fig. 31-10 is a basic amplifier for an electret condenser microphone (refer to
parts list in Table 31-7). The circuit is designed around the common LM741 op amp, which
is wired to operate from a single-ended power supply. Potentiometer R1 lets you adjust the
gain of the op amp, and hence the sensitivity of the circuit to sound. After experimenting with the circuit and adjusting R1 for best sensitivity, you can substitute the potentiometer for
a fixed-value resistor. Remove R1 from the circuit and check its resistance with a volt-ohm
meter. Use the closest standard value of resistor.
TABLE 31-7 Parts List for Sound Detector |
IC1 |
LM741 op amp IC |
Q1 |
2N2222 transistor |
R1 |
500K potentiometer |
R2, R3 |
6.8K resistor |
R4, R5 |
1K resistor |
C1, C2 |
0.47 μF ceramic capacitor |
MIC1 |
Electret condenser microphone |
|
By adding the optional circuit in Fig. 31-11, you can choose up to four gain levels via
computer control. The resistors, R1 and R2 (you decide on their value based on the gain
you wish), are connected to the inverting input of the op amp and the inputs of a 4066
CMOS 1-of-4 analog switch. Select the resistor value by placing a HIGH bit on the switch
you want to activate. The manufacturer’s specification sheets for this chip recommend that
only one switch be closed at a time.
31.8.3 TONE DECODING DETECTION
The 741 op amp is sensitive to sound frequencies in a very wide band and can pick up
everything that the microphone has to send it. You may wish to listen for sounds that occur
only in a specific frequency range. You can easily add a 567 tone decoder IC to the amplifier
input stage to look for these specific sounds.
The 567 is almost like a 555 in reverse. You select a resistor and capacitor to establish
an operating frequency, called the center frequency. Additional components are used
to establish a bandwidth—or the percentage variance that the decoder will accept as a
desired frequency (the variance can be as high as 14 percent). Fig. 31-12 shows how to
connect a 567 to listen to and trigger on about a 1 kHz tone (refer to the parts list in
Table 31-8).
TABLE 31-8 Parts List for Tone Decoder |
IC1 |
567 tone decoder IC |
R1 |
50K 3- to 15-turn precision potentiometer |
R2 |
2.2K resistor |
C1 |
0.1 μF ceramic capacitor |
C2 |
2.2 μF tantalum or electrolytic capacitor |
C3, C4 |
1.0 μF tantalum or electrolytic capacitor |
|
Before you get too excited about the 567 tone decoder, you should know about a few
minor faults. The 567 has a tendency to trigger on harmonics of the desired frequency. You
can limit this effect, if you need to, by adjusting the sensitivity of the input amplifier and
decreasing the bandwidth of the chip.
Another minor problem is that the 567 requires at least eight wave fronts of the desired
sound frequency before it triggers on it. This reduces false alarms, but it also makes detection
of very low frequency sounds impractical. Though the 567 has a lower threshold of
about 1 hz, it is impractical for most uses at frequencies that low.
Being an older part, the 567 has been "obsoleted" by several manufacturers that used to
make it. For the time being, however, you can still purchase 567 chips from most new and
surplus retail and mail-order electronics companies.
Another option is to use a telephone Touch-Tone (known as DTMF) decoder. There are
several chips available, such as the MT8880 (available from Parallax) that can decode the
dual tones of a Touch-Tone phone and output a digital value. An obvious advantage of using
a DTMF decoder over the 567 is the greater number of outputs, allowing you to implement
multiple controls for your robot. The remote control sound source for this chip could be an
old telephone handset that is powered by external batteries and the tones are amplified, or
a microcontroller, like the BS2, which has a DTMFOUT command.
31.8.4 BUILDING A SOUND SOURCE
With the 567 decoder, you’ll be able to control your robot using specific tones. With a tone
generator, you’ll be able to make those tones so you can signal your robot via simple
sounds. Such a tone-generator sound source is shown in Fig. 31-13 (the parts list is Table 31-9). The values shown in the circuit generate sounds in the 48-kHz to 144-Hz range. To
extend the range higher or lower, substitute a higher or lower value for C1. Basic design formulas
and tables for the 555 are provided in the appendices.
TABLE 31-9 Parts List for Tone Generator |
IC1 |
555 timer IC |
R1 |
1 MΩ potentiometer |
R2 |
1K resistor |
C1 |
0.001 μF ceramic capacitor |
C2 |
0.1 μF ceramic capacitor |
SPKR1 |
4 or 8 Ω miniature speaker |
|
For frequencies between about 5 and 15 kHz, use a piezoelectric element as the sound
source. Use a miniature speaker for frequencies under 5 kHz and an ultrasonic transducer
for frequencies over 30 kHz. Cram all the components in a small box, stick a battery inside, and push the button to emit the tone. Be aware that the sound level from the speaker and
especially the piezoelectric element can be quite high. Do not operate the tone generator
close to your ears or anyone else’s ears except your robot’s.
Do not limit yourself to only using a 555 control. As discussed previously, a microcontroller
can output specific frequencies very accurately. Some microcontrollers, such as the
BS2, can be used to output telephone DTMF tones, which will give you up to 16 different
commands for your robot—along with the basic 12 that are on your telephone’s keypad,
there are four additional tone combinations available.
To learn more about . . . |
|
Read |
Computer and microcontroller options for robotics |
|
Chapter 12, "An Overview of Robot ‘Brains’" |
Interfacing sound inputs/outputs to a computer |
|
Chapter 14, "Computer Peripherals" |
Sensors to prevent your robot from bumping into things |
|
Chapter 30, "Object Detection" |
Eyes to go along with the ears of your robot |
|
Chapter 32, "Robot Vision" |