Arduino VU meter/level meter

I just received my new arduino uno in the mail so I'm a newbie trying to learn basic electronics. Please bear with me ..

I am trying to build a VU meter using 8 LEDs and a breadboard audio jack. I've been following a tutorial I found online but I can't seem to get mine to read the proper analog input from the pin the audio jack it is assigned to. When I don't have anything plugged into the audiojack, the LEDs light up on their own and I don't understand where its receiving an input from to make the LEDs light up. Plugging in a microphone in the audiojack has no effect in the way the LEDs are lighting up. I've wired everything up following these instructions and this code. Maybe I'm missing something? I'm not sure but thanks for your help!

Here's the code:
/ Led VU Meter Example

// Version 1.0

// Written by James Newbould

// Edited a little by Zero the Geek 08-13-2013

int led[10] = { 6, 7, 8, 9, 10, 11, 12, 13}; // Assign the pins for the leds

int leftChannel = 0; // left channel input

int left, i;

void setup()

{

for (i = 0; i < 10; i++) // Tell the arduino that the leds are digital outputs

pinMode(led*, OUTPUT);*

  • //Serial.begin(9600); // Uncomment to enable troubleshooting over serial.*
    }
    void loop()
    {
    left = analogRead(leftChannel); // read the left channel
    // Serial.println(left); // uncomment to check the raw input.
    left = left / 50 ; // adjusts the sensitivity *edit My sensitivity is low because my phone does not have a good amplifier bulit in.
    // Serial.println(left); // uncomment to check the modified input.
    // left = 1500; // uncomment to test all leds light.
    //left = 0; // uncomment to check the leds are not lit when the input is 0.
  • if (left == 0) // if the volume is 0 then turn off all leds*
  • {*
  • for(i = 0; i < 10; i++)*
  • {*
    _ digitalWrite(led*, LOW);_
    _
    }_
    _
    }*_

* else*
* {*
* for (i = 0; i < left; i++) // turn on the leds up to the volume level*
* {*
_ digitalWrite(led*, HIGH);
}*_

* for(i = i; i < 10; i++) // turn off the leds above the voltage level*
* {*
_ digitalWrite(led*, LOW);
}
}
}
vumeter.jpg*_

First, what are you seeing on the serial monitor? Are you seeing values that seem to relate to the volume?

Do you have the specs for the audio breakout board? Is it designed for a microphone? If there is no amplifier on the board, you need to use a line-level* output (about 1V), not a microphone (a few millivolts).

The output on your sound card, or any headphone output, or the RCA jacks from a CD player or DVD player are approximately line level.

{

   for (i = 0; i < left; i++) // turn on the leds up to the volume level

    {

     digitalWrite(led, HIGH);

    }

led is an array (not a single variable) and you are never using i in those loops. I think it should be:

digitalWrite(led[i], HIGH);
  • Technically, you shouldn't be running an AC audio signal into the Arduino because you are not supposed to apply a negative voltage (or any voltage above +5V). You probably won't damage the arduino or your audio device, but you'll probably will distort the audio signal.

To fix this, you can use a pair of equal value resistors to bias the input to +2.5V, and a capacitor to block the 2.5V from your audio circuit. Or, a resistor and a pair of protection diodes as shown on the 2nd schematic on [u]this page[/u]. (If you use the protection diodes, I recommend a resistor value of around 10K, instead of the 100 Ohm resistor shown.)

If you choose to bias your input, you'll have to modify the sketch to subtract-out the bias (usually subtract 512 from the ADC reading), and optionally take the absolute value of the negative readings (below 2.5V) or throw them away, etc.