IAN LANG ELECTRONICS

Arduino Project No1.

A Noise Meter

The noise meter measures the ambient volume of sound in its environs, and is set so that the lowest detectable measure of AC voltage from a microphone it detects is approximately 0.5V peak, and the greatest being 5V, the maximum DC supply from the Arduino board. This differs from the traditional 1.23V RMS  in VU meters as developed by Bell Labs for the reason that we are using analogue to digital techniques rather than driving a panel meter, and nor are we going to use the -20 to +3 scale. Nevertheless, using 11 LEDs it gives a very fair picture of the loudness of the surroundings, and by using two red LEDs at the top of the range it can warn when the volume of sound is likely to damage one's hearing.

Here is the external circuitry needed:

Go Back

 

Those of you who are more au fait with transistor circuitry will recognise immediately that this is a Darlington pair. It is needed because the output from the electret condensor microphone is so very tiny that it barely bothers the input pin of the Arduino board and the data remains static. Varying the base of the first transistor causes a slight variation in the voltage at the collector due to its resistor load (10k) and feeding this to the second transistor causes a much bigger variation that the Arduino board can read easily. Now, I like to spread out a bit and build things in small modules sprawling all over the breadboard at first, moving them closer together as I'm sure they work as intended, just like this:

The 5V supply of the Arduino is powering the components on the bigger breadboard and the ground connection comes off it and back to the Arduino too. You can clearly see the electret condensor mic and the transistors. For this I used two TIP31C types, which may seem like overkill but the simple fact of the matter is that you just can't hurt them at this low a power and it's easy to drop the ball with a Darlington.

Yes, I do like biscuits, as my tea-mug has announced by sneaking into this picture. Apart from that , you're going to need to solder up a two-terminal electret condensor mic, and this is explained below:

On the right you will see a diagramatic representation of a two-terminal electret condensor, you can buy these from Maplin, they aren't the cheapest but it's not terribly expensive and they usually keep it in stock in the shop. There are two ready soldered terminals, and one of them touches the case- that one is negative. Take two bits of SOLID CORE wire about an inch to one and a half inches long, and solder one to each terminal. If you use red for positive and black for negative you'll find it much easier to remember which is which.Get a bit of heat shrink, a little shorter than the wires and slip it over them. Using your wife's/mother's/girlfriend's/ sister's/general female acquaintance's hairdryer (because if you're a bloke you don't own a hairdryer or if you do you don't admit it) drift some hot air over it and the heatshrink will go tight, keep the wires nicely rigid and make your mic very breadboard friendly indeed. You can get heat-shrink at Maplin too; buy a lucky bag and you get all sorts of different sizes in convenient lengths.

When you've done, you'll end up with something like the picture on the left. Slips in and out of the breadboard like a buttered pig and gives a very good connection.

Wire up the LEDs in exactly the same way we've always done on the Arduino board, anode to pin and cathode to ground via a 560R resistor, and put the bottom of the range LED on pin 12 (i.e the one that will shine when it's quiet).

When you're done building the LED circuit and the external amp (the mic and transistors, etc) take a little portable FM radio and tune it to Radio 4. Put it not too far away from the mic and turn the volume up and down. Turn the volume up quite high and move the radio closer to the mic- what should happen is that the closer you get to the mic, the more LEDs should light, and the further away the less LEDs.

The microphone is actually a powered capacitor and as the volume of sound around it increases so does the air pressure. This causes a plate to move, increasing or decreasing the capacitance, which causes a small variance in voltage, turning it into an AC voltage for all practical purposes, which the capacitor feeds to the base of the first transistor and starts the reaction. At the collector of the second transistor we take the output and feed it to pin A0.

Between the junction of the two resistors before the microphone, you may want to stick a 10 uF capacitor with its negative leg going directly to ground. Normally it won't make that much difference, but it might remove some transients that could cause problems later.

Time to look at the code that works it then:

 

int PinValue[] ={12,105,11,186,10,279,9,372,8,465,7,558,6,651,5,744,4,837,3,930,2,1015};

int j;

int value;

void setup() {}

 

void loop(){

  value = analogRead(A0);          

for (j=0;j<21;j=j+2){

  if (value <PinValue[j+1]){

digitalWrite(PinValue[j],LOW);

}

else {

digitalWrite (PinValue[j], HIGH);}

}}

 

I've deliberately kept this as small and tight as possible as we're moving on to more complex projects shortly and now is a good time to start learning how to strip your code down. This occupies just 938 bytes.

 

The key to understanding the code is the array on the very first line:

 

int PinValue[] ={12,105,11,186,10,279,9,372,8,465,7,558,6,651,5,744,4,837,3,930,2,1015};

 

There are two pieces of information included in this array, a pin number (postions 0,2,4,6,8,10,12,14,16,18,20) and the value of the analogue input signal in digital terms at which that pin is going to become high (positions 1,3,5,7,9,11,13,15,17,19,21).

 

The first line of the loop is:

 

  value = analogRead(A0);    

 

The Darlington pair and resistor at the collector of the second transistor attached to the back end of the microphone circuit will output a value from lesser than 0.5V to as much as 5V, but the analogue inputs can only count digitally,  in discrete steps from 0 to 1023. If the top voltage is 5V, then this is 5000 mV, and so dividing 5000 by 1024  gives us 4.8828125 or 4.9 to 1 decimal place; and therefore 4.9 mV is a digital reading that borders on 1. Following on, at  500mV (or 0.5V) the result is going to be 102. This is quite far down the range, and so the microphone will be picking up very quiet sounds. Similarly at 4500 mV, (4.5V) the digital value of the microphone reading will 922 (multiplying by 4.9 actually gives a figure of 921.6 but the digital reading can only be an integer so it rounds to 922) and in this case the microphone will be picking up sounds that are quite loud. This translates to lighting (or not) LEDs by the conditional and the nested if.....else statement inside it. Line by line:

 

for (j=0;j<21;j=j+2){

 

meaning j will now go through 11 cycles (0-21, but up by two each time so it goes 0,2,4,6,8,10,12,14,16,18,20 ) to read the array positions.

 

  if (value <PinValue[j+1]){

 

As you remember the pin number and then it's value are in the array. So, if the value if the analogue reading (in digital terms) is lesser than the value recorded in the j + 1 th position in the array:

 

digitalWrite(PinValue [ j ],LOW);

 

and consequently the LED attached to that pin is extinguished. If it's not lesser than it must be equal to or greater than the value in the j +1 th position so:

 

 

else {

digitalWrite (PinValue[ j ], HIGH);}  

 

 

 

and consequently the LED attached to that pin is lit.

 

The loop repeats itself for as long as power is applied, and since the entire processing run takes only a few milliseconds, it looks to human eyes as though the response is instantaneous.

 

Practical applications could be a noise meter for workplaces, a comparison meter for hifi systems or simply an independent bar graph for music sources.

 

 

Ian Lang, September 2011