# Electronic – arduino – How to get +5v for loud noise, 0v for silence from Electret Microphone (or other components)

amplifierarduinomicrophonemicroprocessornpn

I have been asking a few questions here to get to a proper one, the initial questions I asked are linked to at the end. I used Fritzing to make up some schematics of my initial thoughts, but at the very least I need help with the values on the components, which I only vaguely understand and picked what seem to be reasonable or common values.

Basically, I have an Arduino that has 6 analog inputs. It uses a 10-bit ADC to read the voltage on any of the analog pins, so 0 = 0v, 511 = 2.5v, and 1023 = 5v, and all the values in between. It makes a LINEAR DC reading, so I'm not looking for logic 1-0 here.

I have this hooked to LED lights, and I want to make them respond to music. What I want is maximum resolution with minimum components, and I think I'm using WAY too many components and making this WAY too complex. Perhaps Electret microphones are not what I want here, I'm open to something else. I'd prefer to not use op-amps to conserve space on my PCB.

What I want is a simple noise level sensor. I'm not looking to reproduce the audio, or have clarity or anything, but I would like, as close I can get:

• Perfect Silence = as close to 0v DC (stable, not AC) as possible
• Medium Noise = Around 2.5v DC (stable, not AC)
• Loud Noise = as close to 5v DC (stable, not AC) as possible

I understand with a BJT that the best I can get is going to be 0.6v to 4.4v, but this is acceptable enough. What is not, however, is half of the wave, 0.6v to 2.5v. This seems to be wasting half of my available resolution for no reason. However, if there are other setups than a BJT that can get me closer to 0v-5v, I'd be interested in giving them a shot; as long as they're simple.

Here's a simpler one, that I hope that this is possible, but it requires the electret signal to have enough amplitude to drive the envelope detector circuit (diode, resistor and capacitor) to get only the positive half. I don't think it can because of the diode's forward drop, but perhaps this can be rearranged or done before the output cap? What should the values of the envelope detector and amplifier resistors be? Should a sensitivity potentiometer be placed on the signal, or RE, or RL, and what should it's value be? Linear or Logarithmic?

However, perhaps the electret output can't survive the envelope detector, sensitivity shunt, and still drive a NPN transistor. If not, here's a more complex version. Do I need to go this route? Does getting my desired output from the circuit really really require all these components?

Here are some of the past questions I asked before I more fully understood what I was trying to articulate, for more details. Here's what the envelope detector is 'supposed' to do, and I'm not sure how to tune it for the electret output:

Although you could do this whole thing with just an amplifier and a microcontroller (Arduino), as far as I can see, you want the analog option. I have tried to create a circuit that outputs the voice level on the microphone. The range is from 0V to 4V. However, you can upgrade it easily to 0V to 5V by just changing the OP-AMP. Now, let's go into it;

First of all, I have replaced the transistor amplifier with the OP-AMP. Here is what I came up with;

This is a simple inverting amplifier with a gain of 100. Here is the formula to calculate the gain;

$$V_{out}=-\dfrac{R_f}{R_{in}}*V_{in} = -\dfrac{100k}{R_{in}}*V_{in} = -100*Vin$$

As you can see, U1 takes the input signal, inverts it and then multiplies it with 100. You can change R2 or R3 and you will see that the gain of U1 changes. Inversion of the input signal does not matter here, as you will understand later on. Let's look at the output of this amplifier, and you will see that there is a big growth on the input signal.

In the above graphic, you will see that output has a DC offset voltage of 2.5 volts. That is because of the virtual ground we have used. If we create a virtual ground, that means we carry the ground to an another voltage level. In this case we have moved it to 2.5 V. With the new configuration, we have created something that looks like -2.5 V, 0 V, and 2.5 V to the circuit. In order to achieve this, I had to create a new voltage rail of 2.5 volts. Since that voltage rail will not supply much power, (less than 1 mA), it is easy to create;

Notice the negative feedback on the above circuit. That will give the OP-AMP the order to make \$V+=V-\$. OP-AMP will do its best to achieve this equation. Thus, the output will be 2.5 V, or in other words, half the supply voltage. And that is our new ground point.

After the amplification, we should put the signal on to an "envelope detector" or in other words, "envelope follower". This will get the level of the signal, as you wish and as you showed in the picture in your question. Here is what a basic envelope follower looks like:

It looks all great, however, notice that here, D3 is a diode and it drops about 0.6 V on itself. So, you loose the voltage. In order to overcome this, we are going to use what is called the "super-diode". It is super, since the voltage drop is almost 0V! In order to achieve that, we include an OP-AMP with a diode, and that is all! The OP-AMP will compensate the voltage drop of the diode, and you will have an almost ideal diode;

Since there is negative feedback in this configuration, U5 will try its best to make \$V+=V-\$. So, whenever the input is say 3V, it will make its output 3.6V to compensate with the 0.6V voltage drop on D3. So, the output of this super-diode, hence the \$V-\$ input will be equal to its input voltage \$V-\$. However, when the \$V+\$ input is negative, D3 will not allow U5 to make the output negative. Also note that the negative rail for U5 is GND, which is 0 V. It will not be able to go below 0 V in any case, already. It works just like an ideal diode!

Now, change D3 in the above envelope follower circuit with a super-diode, and you have a better envelope follower! Let's look at our result;

We are getting close. As you can see, the output of the envelope follower, which is the red line, can go from 2.5 V to 4 V. 2.5 V is no-sound, 4 V is loud-sound and 3.25 V for medium-sound. To scale that to what you have wanted, we can subtract 2.5 V offset voltage and scale it. So, when you subtract 2.5 V, it becomes; 0 V for no-sound, 1.5 V is loud-sound and 0.75 V for medium-sound and so on. After that, if you multiply this with about 3, you will get what you exactly want. 0 V for no sound, 2.5 V for medium-sound and 5 V for loud-sound. To recap, what we want is this;

\$V_{out}=(V_{in} - 2.5V) * 3 \$

In order to achieve this, we will use a differential amplifier or in other words a "subtractor".

When resistors, R1 = R2 and R3 = R4 the transfer function for the differential amplifier can be simplified to the following expression:

$$V_{out}=\dfrac{R_3}{R_1}*(V2-V1)$$

If you make V1= 2.5V and R3/R1 ratio 3, then you will get the output you wish.

Here is the complete schematic that will do what you want:

I have used LM324 OP-AMP here for simulation purposes. That will limit the maximum output voltage to 4V. In order to have full range output, you should use a rail-to-rail output OP-AMP. I would suggest MCP6004. Change R1 and R2 until you have the desired result. Here is what I got with the simulation:

Now, when measuring these values in ADC, you will not get a linear sense, instead sound is better understood logarithmic, since our ears hear that way. So, you should use decibels. If you are not familiar with decibels, here is a great video tutorial about it.

A quiet room, for example is measured to be around 40 dB. A party in a room will make the room's level go up to 100 dB, or maybe 110 dB. In this website, you can find great info about it, from where I also have embedded below image. Think about the decibel levels and experiment with the voltage output of the circuit. Then, calculate the ADC resolution that you will need. Probably, you will be fine with an 12-bit ADC.