Sound Sensor -- Analog

In this exercise we'll see how to detect sound in an analog fashion. In other words, we'll come up with a circuit to extract the amplitude envelope of sounds, convert that to a varying DC voltage, and finally change that to a binary number using the analog-to-digital converter within the PIC microcontroller. Continuously changing levels are accommodated by this project; if all you need is simple sound detection (ON/OFF), we can simplify things considerably. That'll happen in a later project.

Let's see how it works. Check out the schematic.

An electret microphone is used. I got mine for 50 cents from All Electronics some years ago. You'll note that this requires a bias voltage to operate; that's provided by R1 running to +15V. The audio output is coupled to preamplifier IC2. Note how C3 blocks that bias voltage just mentioned.

The amplifier not only buffers the mic output, but boosts the hell out of the signal, in fact by a factor of 101. This then feeds potentiometer R5 which lets you set the sensitivity. The amplified audio signal is then AC coupled to the precision fullwave rectifier configured around IC3a. The nice thing about such a topology is that the usual diode drops are obviated. Incidentally, notice that this fullwave rectifier is inverting; what comes out is a negative version of both the rising and falling portions of the audio.

IC3b boosts the signal yet again. (Remember, the microphone signal we started with is minuscule). Equally important is C2 which filters the rectified waveform, transforming it to a DC level. The value of this cap is a good compromise between smooth filtering and fast response for most audio applications. Observe that the amplifier configuration is inverting, hence what comes out now is a positive voltage.

Now I've deliberately pushed the voltage output up to the maximum swing of the TL072 (about +13.5V), just so we can drop it back down again to +5V by means of voltage divider R11/R12. The point is, we'll be feeding this voltage to the PIC and want to be damn sure we don't exceed +5V. The properly massaged level is sent to the PIC's ADC at pin 1 of IC1, and the program then takes care of converting the sensed voltage to a binary number. The resulting level is finally depicted on the LED dot graph (not shown in the schematic), the same dot graph used in the preceding exercise (Homemade Pressure Sensor).

Of course, the op-amps will require bipolar supply voltages. Be very careful not to mix these up with the PIC's +5V supply. Moreover, I recommend that you do not connect the envelope extractor to the PIC until you've tested the tie point of R11/R12 to ensure the signal there stays strictly between 0V and +5V. Only then should you complete the circuit by feeding the signal to pin 1 of the PIC.

Here's a short video showing the circuit in action:

You'll note that it's quite sensitive and responsive. The LED dot graph is just for illustration purposes, but obviously there are many more useful things the circuit could be used for!

Click to get the source code.
Click to get the schematic PDF.

Next Project: Temperature Sensor -- Analog

No comments:

Post a Comment