CHAPTER 31

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.
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.
images
images
 
IC1  
LT1007 low-noise operational amplifier (Linear Technology)
R1  
330K resistor
R2  
4.9K resistor
R3  
100-Ω resistor
C1  
0.1 μF ceramic capacitor
 
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.
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.
images
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”).
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.
images
 
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

 
images
images
images
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.
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.
images
 
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
 
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.
images
TABLE 31-4   4051 Truth Table
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.
images
 
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
 
images
 
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.
images
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.
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.
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.
images
 
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.
images
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.
images
 
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.
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.
images
 
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.