3 minute read
How to Use a Microphone Module
218 Hacking Electronics
probably want to make yours longer. This is not a problem, unless you plan to make it longer than a few yards or meters.
The 3.5mm plug is of the plastic molded variety, reclaimed from some unwanted lead. The first step is to strip both leads (Figure 9-5a). Note that the stereo plug has two screened connections in one twin cable. The screened ground connections of both channels of the stereo plug can be twisted together.
Tin the ends of all the leads, and then solder the resistors together, as shown in Figure 9-5b.
Next, solder the stereo and mono leads to the resistors, as shown in Figure 9-5c, and cut and tin a short length of wire to bridge the ground connections. Solder it into place (Figure 9-5d) and then wrap everything in insulating tape, taking care to put tape in between any places where wires could short together (Figure 9-5e).
Figure 9-6 A microphone module
How to Use a Microphone Module
Microphones (mics) respond to sound waves, but sound waves are just small changes in air pressure, so it is not surprising that the signal you get from a mic is usually very faint. It requires amplification to bring it up to a useable level.
While it is perfectly possible to make a little amplifier to boost the signal from your mic, you can also buy a mic module that has an amplifier built in. Figure 9-6 shows such a module.
The mic module just requires a supply voltage between 2.7V and 5.5V. This makes it ideal for interfacing with an Arduino.
In Chapter 11, you will find out a bit more about oscilloscopes. But for now, here is a sneak preview of what an oscilloscope will display (see Figure 9-7) when connected to the mic module while a constant tone is being generated and the module is supplied with 5V.
Figure 9-7 The output of the microphone module
CHAPTER 9: Audio Hacks 219
Figure 9-8 The schematic diagram for a mic module
The oscilloscope is displaying the sound. In this case, a constant and rather irritating tone of 7.4 kHz. The horizontal axis is time, and each blue square represents 100 microseconds. The vertical axis is the voltage and each square is 1V. The output of the mic module is a voltage that varies very quickly between about 1.8V and 3.5V. If you draw a horizontal line straight down the middle of the waveform, it would be at about 2.5V. This is halfway between 0V and 5V. So if there is no sound at all, there will just be a flat line at 2.5V, and as the sound gets louder, the waveform will swing further and further either way. It will not, however, go higher than 5V or lower than 0V. Instead, the signal will clip and become distorted. The mic module shown is sold by SparkFun (BOB-09964). The schematic for this, along with all its design files have been made public. Figure 9-8 shows a schematic for a typical microphone pre-amp. The chip at the center of this design has a similar circuit symbol to the comparator you used in the “How to Detect Noxious Gas” section at the beginning of Chapter 8. However, it is not a comparator; it is an amplifier IC of a type known as an “operational amplifier” (or “op amp” for short).
Whereas a comparator turns its output on when the “+” input is higher than the “–” input, an op amp amplifies the difference between the “+” and “–” inputs. Left to its own devices, it amplifies this by a factor of millions. This means that the tiniest signal or noise on the input would be turned into meaningless thrashing of the output from 0 to 5V. To tame the op amp and reduce its amplification factor (called “gain”), something called “feedback” is used.
The trick is to take a portion of the output and feed it into the negative input of the op amp. This reduces the gain to an amount determined by the ratio of R1 to R2, shown in Figure 9-8. In this case, R1 is 1MΩ and R2 is 10kΩ, so the gain is 1,000,000 / 10,000 or 100.