Lab 3: The Synthetic Psychology of Sound Localization

Return to the lab overview, or move on to task 5.

Task 4: Build an artificial auditory system (i.e., a microphone!)


Although the voltage across the two pins of our microphone will fluctuate based on the input sound, we would like to amplify this so that the Arduino can actually read the signal. This can be a bit of a complex circuit to think about at first to we will build it up slowly. This figure gives an overview of what the circuit will do:

First, the voltage changes due to the mic (step 3 in the figure) are relatively small (fractions of a millivolt usually) we would first like to move them into a better range to use as input to our amplifier (step 4 in the figure). We'll do this a couple times in the lab and refer to it as "stepping up" the signal, since we are changing the average voltage value without changing the variance. The amplifier stage will "turn up the volume" on the voltage changes by making them span a larger range (step 5). Thinking back to your statistics class, this step does effect the variance! The output of the amplifier will be centered at 0V and range positively and negatively. However the Arduino can only read positive values in the range 0-5V. Thus, in the final stage, we will "step up" the signal again to range between 0V and 5V (step 6 in the figure) which is the type of input signal that the Arduino analogRead() function is designed to measure (step 7 in the figure).

Build a microphone circuit

In order to add the microphone to the Arduino, we need a basic microphone circuit that provides voltages with the appropriate values. This will cover steps 1-4 in the overview above. A classic way to do this is with a "voltage divider" circuit (see below). A voltage divider simply involves a voltage source (e.g., battery, or in our case the +5V pins on the Arduino chip) and two resistors. The resistor are connected in series (i.e., in a row or sequence... if the wires are the resistors "arms", imagine they are holding hands in a line). The voltage we are interested in will be measured at the middle point between the two resistors (we'll call this value Vout). The value of Vout as a function of Vin (the voltage provided by the battery or Arduino) is given by the equation on the right. We will choose R1 and R2 so they are the same value, thus Vout will be 1/2 Vin. However, other fractions are also possible by choosing the right resistor. This circuit is so popular, it even has its own Wikipedia page!

The figure below (click to enlarge) shows the abstract circuit diagram for one voltage divider circuit, the theoretical relationship between the resistor values, the input voltage (Vin), and the output voltage (Vout), along with an example of two voltage dividers wired up on you Ardunio breadboard. Ignore the colors on the resistors, those are just for illustration. As indicated in the circuit, you should select 100KOhm resistors. This page has some helpful info about reading the colors stripes on the side of a resistor element so you can identify the value.

If you hook up a circuit like this and measure the voltage from ground to Vout using a multimeter you should see that it measures around 2.5V.

We can add to it by putting our microphone in parallel with the first resistor (R1). Parallel means that the "arms" of the component are holding both hands like you would if you were slow dancing with someone. Once the microphone is hooked up the voltage will be a little lower than 2.5V at Vout terminal due to the influence of the microphone circuit which has it's own resistance. In addition, the voltage at each Vout will now fluctuate (in fractions of millivolts) due to the sound pressure being registered by the microphone element.

Good job! You've created an artificial ear!

Build an amplifier

Although you could connect the Vout terminals from the last circuit above directly to the "ANALOG IN" pins on the breadboard (A0-A4 at the bottom right) and then read the voltages from them using analogRead() in your Ardunio code, the voltages fluctuations coming from this microphone circuit are too small to be read reliably except maybe for really loud sounds. Thus, we need to give our robot a hearing aid (i.e., amplifier) which, like the amplifier in a car stereo, makes the sound "louder" (but in terms of voltages rather than in terms of the energy in the sound waves).

A full description of amplifier circuits is beyond the scope of this article, although there are some a number technical guides online []. The main point for our purposes is simply that an amplifier can be built out of a simple a integrated chip along with a couple resistors.

The circuit for the amplifier is shown above in isolation. It involves five new components. Two should be familiar to you (3 resistors - the jagged lines, 1 capacitor - the parallel lines), but the large triangle component in the middle is new. This is an "op-amp" or "operational amplifier." Op amps can be used in a variety of ways but in this case we are going to use it to amplify the voltage coming in on the "Vout" pin from our microphone circuit above. The amplified signal will be available at the "Vout (Amp)" pin.

The op-amp chip we are going to use is known as a LN3205N. This chip has 10 pins around the edges and inside there are actually four different op-amps! This is great since we need at least two amplifiers (one for the left "ear" and one for the right "ear"). Thus, we will use two of the amps contained within the LN3205N.

One important thing about opamps is that they need their own external power. This is reflected in the circuit diagram with the +VCC and -VCC inputs. On the LN3205N chip itself all four opamps get their power from the same +VCC and -VCC pins which are located on pins 4 and 11.

The important aspect is that the opamps can get really HOT and start burning if connected up incorrectly. Thus, you want to be very careful to wire things up as I describe here. If you make a mistake, you might start smelling smoke or could burn your hand! The key is that the +VCC must have a positive voltage coming from your Arduino. The -VCC must be connected to ground (GND) or a -5V supply (see this post for how to create a negative voltage from Arduino... I will provide this circuit for you for the lab.). If you reverse this (connect pin 11 to pin 4 and vice versa, smoke and destruction will happen). Pay careful attention to the orientation of the chip to known which side is which. There is a little half-moon size "knick" one edge of the opamp as in my diagram below. If you orient that downward, the +VCC pin will be in the middle of on your right and the -VCC pin will be on your left.

The following figure gives an overview of where we are now in the hardware steps, the abstract circuit design, and how it will look wired up in your Arduino. Remember don't trust the resistor colors in my diagram! Look up the values on the abstract circuit design and match them with the names (R1, R2, etc...). Also note that a capacitor (yellow component) goes between the output stage of the microphone and the input to the amplifier. This is illustrated below.

Great, if you have this working, you should have a nice clear signal coming from the output of the amplifier. We will test this in class using the oscilloscope. If I connect one pin of the oscilloscope to ground and the other to the Vout pin labeled in the illustration (and repeat for the second channel) and I whistle at my robot, I should get nice sinusoidal signal. If you have this working, nice job!

Wire it up

In the final step, we want to plug the output of our amplified into the "Analog inputs" on the Arduino so we can do further processing of the information in software. However, remember that the output of our amplifier is zero-centered. The Ardunio likes to read signals that range between 0 and 5V. Thus, we ill need to do a final "step up" operation to add a few volts to the output. Luckily you are already an expert in this having created a voltage divider above!

Here is the final circuit all wired up! Looks scary but you've made it!

Q5: Have your robot checked with me using the oscilloscope to verify everything is working. It will likely not work on the first try, but we will work together to help debug!

Return to the lab overview, or move on to task 5.
Copyright © 2013 Todd Gureckis, Diagrams and schematics of the Parallax robot come from the Parallax website, much excellent material was taken from David Heeger's course notes on sound localization