microphone sensitivity

Good night,

I am trying do a vumeter with arduino UNO and the microphone module.

I get it, but it is very sensitivy and with the music the valor of the analogic input is between 1023 and 30.

i dont get control de sensitivity.

the leds are all on or off but very few times and by a shortest time you can see a increase light.

can anybody tell me how do the vumeter?

the code create for me is it that you can see below.
I am a beginer with arduino.

thank you very much

int led1 = 2;
int led2 = 4;
int led3 = 6;
int led4 = 8;
int led5 = 10;
int led6 = 12;
int micro = 0;
int prueba = 7;
int intensidad;

void setup() {
pinMode (led1, OUTPUT);
pinMode (led2, OUTPUT);
pinMode (led3, OUTPUT);
pinMode (led4, OUTPUT);
pinMode (led5, OUTPUT);
pinMode (led6, OUTPUT);
pinMode (prueba, OUTPUT);
Serial.begin (9600);
}

void loop() {
intensidad = analogRead (micro);

digitalWrite (prueba, HIGH);

if (intensidad < 1023){
digitalWrite (led1, HIGH);}
else { digitalWrite (led1, LOW);}
delay (5);
if (intensidad < 600){
digitalWrite (led2, HIGH);}
else { digitalWrite (led2, LOW);}
delay (5);
if (intensidad < 400){
digitalWrite (led3, HIGH);}
else { digitalWrite (led3, LOW);}
delay (5);
if (intensidad <100){
digitalWrite (led4, HIGH);}
else { digitalWrite (led4, LOW);}
delay (5);
if (intensidad < 100){
digitalWrite (led5, HIGH);}
else { digitalWrite (led5, LOW);}
delay (5);
if (intensidad < 30){
digitalWrite (led6, HIGH);}
else { digitalWrite (led6, LOW);}
delay (5);

Serial.println (intensidad);

if (intensidad < 1023){
  digitalWrite (led1, HIGH);}
  else { digitalWrite (led1, LOW);}

Doesyourspacebarnotwork?
Isyourenterkeybroken:

That mess should be:

  if (intensidad < 1023)
  {
    digitalWrite (led1, HIGH);
  }
  else
 {
   digitalWrite (led1, LOW);
 }

and the microphone module.

What "microphone module"?

You should test the microphone input data with a simpler sketch. Then work on the program that uses it. You can't solve two problems at the same time easily.

Paul,

I prefer write the code as you see, it is more easy to read for me.

PaulS:

if (intensidad < 1023){

digitalWrite (led1, HIGH);}
 else { digitalWrite (led1, LOW);}



Doesyourspacebarnotwork?
Isyourenterkeybroken:

Byhiswritingstyleit'sobviousEnglishisn'thisnativelanguage.

So maybe help instead of snide would be good?

Just sayin'

Code looks ok for lighting up LEDs as the amplitude of that sample is read.

However are you pushing the microphone through an amp or is it wired directly to the Arduino? the signal may be a little weak without an amp.

Also how are you managing the zero crossing on the wave? The wave will oscillate around the zero volts. You'll need to offset to get it within the 0-5v that the Arduino pin expects.

the leds are all on or off but very few times and by a shortest time you can see a increase light.

The basic problem is that you are sampling a continuous audio waveform and displaying the level of that particular sample. You could have a constant tone, but every time you take a reading you can read any "random" value in-between zero and the peak value.
The [u]Audacity Website[/u] has a good introduction to digital audio showing how you sample the waveform and then "connect the dots" when you want to reproduce the analog waveform.
For your application, you'd probably like to get the peak. We don't know how fast your loop is running so we don't know the sample rate.

One solution would be to make many readings (maybe 100 or 1000 readings) and find the peak value out of those readings.* After you find the peak, then decide which LED to turn-on. Leave that LED on and start the loop over. A delay of about 1/10th of a second may help too by simply slowing-down the changes. i.e. Take the 100 readings as fast as you can, and then hold the LED display for 1/10th of a second.

I have a VU meter lighting effect (as well as some other lighting effects) and my solution is to use a [u]peak detector circuit[/u]. This circuit takes the positive audio peak and converts it to a changing DC value. With a time constant of about 1/10th of a second, I can read the "volume" about 10 times per second instead of sampling the actual audio waveform thousands of times per second.

As tammytam said, depending on your analog circuit, the input may be biased. Since the Arduino cannot read the negative half of the waveform,** it's common to bias the input at 2.5V. That means silence reads about 512 and the audio signal varies above and below that value.

  • You don't need to save all of the readings... Just save the peak and if the new reading is greater than the existing peak replace the peak value with the new peak. (Then, reset the peak to zero next time you start the loop.)

** The Arduino can be damaged by negative voltages and/or the audio signal can be distorted if you feed-in an AC signal.

DVDdoug:

  • You don't need to save all of the readings... Just save the peak and if the new reading is greater than the existing peak replace the peak value with the new peak. (Then, reset the peak to zero next time you start the loop.)

I would rather sample the peak continuously, and decrement the "existing peak" variable by a small amount every sample. It would be smoother, and you could control the decay time constant.