Help with LED VU Meter

My initial problem of having the LED's not light up is already fixed, I just didn't connect ground to a few LED's so it works now. I am just curious as to why the system stops working if there is too much input. Is there an error message or anything as to why this happens?

Most likely you overdrive / overload arduino with your audio input signal.
Data sheet for Atmega328 says that voltage present at any input, including analogs must be:

Voltage on any Pin except RESET with respect to Ground .........-0.5V to VCC+0.5V
*NOTICE:
Stresses beyond those listed under “Absolute Maximum Ratings” may cause permanent dam-
age to the device. This is a stress rating only and functional operation of the device at these or
other conditions beyond those indicated in the operational sections of this specification is not
implied. Exposure to absolute maximum rating conditions for extended periods may affect
device reliability.

Audio signal is AC or Alternating current, which means it's positive for half period of time and negative for other half period.

edited:
Arduino couldn't tolerate negative voltage, if it's more than 0.5V, so bare minimum protection circuitry should include schottky diode + resistor to cut off this.
For positive voltage, maximum is Vcc +0.5V, it could be 5.5V ( or 3.8V for boards with power line 3.3V). The easiest way to protect against "overdrive" in positive area is a zener diode at the input Vz = 5.1V , 1N5231B, (Vz = 3.6, 1N5227B, for boards with VCC = 3.3V).

And next, it's nice to have envelope detector at the input, as amplitude of the audio signal varying too fast for arduino to catch up with. Microprocessor has other stuff to do, it doesn't measure voltage continuously, and simple capacitor + resistor would help to hold peak till arduino find a time to check it.
You can buy a VU shield, or build your own according to attached schematic.

I read this tread...interesting project...

So Wally_z.... the analog pin CAN NOT go negative.. ok Use Magician zener protection circuit and here an idea call a signal "ridding" on a DC line. Most Line Out signal , the voltage is about 3 V peak to peak max volume ( at my sound card output ) It mean 1.5 V plus and 1.5 V negative. So you simply ADD a DC voltage to it. Arduino is 0 to 5. 5 V window , signal 3 V <-- Can fit the "window" Got me so far ? So add a 2.5 V DC by using a voltage divider. A 47 K + 47 K should be fine. Therefore the Arduino pin will "see" a 2.5 V when no audio signal is present. At max level, the pin will "see" 2.5 V + 1.5 V = 4 V ( positive - up side ) and 2.5 - 1.5 = 1 V ( negative - down side ) THAT is call a Sine Wave "ridding" a DC line or Voltage. I hope you understand me so far.

So when a leftlevel= analog( pinanalog); ----> leftlevel = 0 --> 0 V at analog pin leftlevel = 1023 --- > 5 V at analog pin leftlevel=512 ---> 2.5 V at analog pin. Ok so far... AT max level - 4 V --> leftlevel = 820 positive swing, 1 V --> leftlevel =204

The analog pin doing this : 5 V / 1024 = 4.88 mV per step ( bit ) a step is a leftlevel = 1.

I hope this help.

It require cap at the input. Initially, I thought just to post a link:
http://interface.khm.de/index.php/lab/experiments/arduino-realtime-audio-processing/
(I like this drawings, post it all the time).
Then I realize, if someone (newbe or artist, who has no clue what line level is) connect input to speakers, there is no protection from "too much" level, and arduino would have a heart attack again as it was described, by blinking led on pin #13 rapidly. =(
I start to google, trying to find a some kind of schematics to save time not to draw it. I was not able to find anything for couple hours! This is why I create it myself. :smiley:

@Magician. I've heard of diodes, but never used on except LED's. Is there a certain type of diode to use?
(First schematic) I see a diode in the line, and then a resistor. What type of diode (rating? zener or whatever its called?)
(Second schematic) Now there is a second diode saying "5.1v" going to PGND which I'm guessing is ground but I don't know what PGND is. (I googled PGND and i'm still confused. What's with the 5.1v?)
(Third schematic) Now it gets a bit complicated. What is an envelope detector and why would I need one?

How does the "protection" of these schematics vary? My Arduino is working fine, no problems, I don't have the signal maxed out or anything so if I don't turn it up it'll be fine.

@Techone the analog pin is apparently getting negative voltage from the AC coming from the audio signal. Does hZ in electricity matter for this kind of thing? (hZ or Hertz, is electricity flowing through a wire, at all times, not sure about AC, the electricity is off for 60 times a second and on for 60 times a second. I guess AC is a bit slower than that to consider it AC.)
I've heard of voltage dividers. Don't speakers work by using the wattage in a circuit instead of the voltage?

You really need to slow down and start understanding basic concepts before you damage your Arduino or yourself (or, more likely, both)

Watts (W) measure the power in a system, and are the product of volts (V) and amperes (A).

Hertz is the unit of frequency.

My Arduino is working fine, no problems

That may not actually be the case - you have no way of knowing.

Is there a certain type of diode to use?
(First schematic) I see a diode in the line, and then a resistor. What type of diode (rating? zener or whatever its called?)

Good question, I slightly modified my drawings, now it include words "schottky" diode.

(Second schematic) Now there is a second diode saying "5.1v" going to PGND which I'm guessing is ground but I don't know what PGND is. (I googled PGND and i'm still confused. What's with the 5.1v?)

Yes, PGND is a ground, it marked so in gEDA, never mind. "5.1V" is zener diode voltage, for example, 1N5231B has such Vz.

(Third schematic) Now it gets a bit complicated. What is an envelope detector and why would I need one?

Look for on-line resources, wikipedia or similar.

Don't speakers work by using the wattage in a circuit instead of the voltage?

Voltage and wattage bind by formula: P = V^2 / R.

AWOL:
You really need to slow down and start understanding basic concepts before you damage your Arduino or yourself (or, more likely, both)

Watts (W) measure the power in a system, and are the product of volts (V) and amperes (A).

Hertz is the unit of frequency.

My Arduino is working fine, no problems

That may not actually be the case - you have no way of knowing.

That is true, but I see no problems.

@magician Alright, I will look into getting a few diodes to try this out. Just a few questions. Where PGND is, where would that go, to ground on the Arduino, along with the audio signal ground? Does the whole "minimum protection" circuit go on JUST the signal wire(s) or use one on each wire coming from the signal? I don't think ground would get this but I would like confimation on what to do. I checked Radioshack.com and there is no such thing as a Schottky diode, or 1N5231B. Could I use a Zener instead? Or a 1N4733A, 1N5399-S, or 1N914/4148? If I can use one of those I'll run to my Radioshack and get one and build this. I might do the Envelope Detector, for the diode put in backwards is it a Zener? I'm just curious as to what the line on the left side is, maybe it means its backwards? I can't find that specific symbol. For the capacitor im guessing a polarized 1uF electrolytic? Thank you for all you've done for me so far.

Ground on arduino board usually mark GND, should be a few (3?) of this pins available. And your audio jack ground wire should be connected to any of this pins, of course. Shown circuitry is for one analog pin in use, it's mean if you combine left/right channel at the audio jack, you need only one resistor + diode.
The same time for separate left / right stereo channel connected to different analog inputs, you'd need two protection circuits.
1N4733A - zener 5.1V , o'k
1N5399-S - general rectifier, not o'k
1N914/4148 - could works, not so efficient as schottky

I might do the Envelope Detector, for the diode put in backwards is it a Zener? I'm just curious as to what the line on the left side is, maybe it means its backwards? I can't find that specific symbol.

http://www.kpsec.freeuk.com/symbol.htm

And capacitor is electrolytic.

@Magician. Awesome, i'll do that then. Thank you for helping me. Just 2 last questions, I will be using two of the same type of diode correct? And the second diode in the circuit with the extra line on the symbol goes in BACKWARDS correct?

If you choose schematic #2 with two diodes, I'd suggest to increase value of resistor up to 100 kOhm, so with lower current, forward voltage would stay below 0.5V across diodes.
If you gonna follow #2 with zener + resistor and diode, than actually you don't have to install diode if it's not schottky, only resistor and zener. Don't have current/voltage chart for this type of zener, probably, you would have to lower resistor value to 1 kOhm or so if there would be a problem with lower reading of the signal level at the input.

And the second diode in the circuit with the extra line on the symbol goes in BACKWARDS correct?

Yes, it's how zener works, in reverse area.

@magician Is there anything I have to change in schematic #3? Also, if I use a resistor of different resistance, will it decrease performance?

It require cap at the input. Initially, I thought just to post a link:
http://interface.khm.de/index.php/lab/experiments/arduino-realtime-audio-processing/
(I like this drawings, post it all the time).

@ Magician

Thank for the link. I will use it.

@ wally_z

What audio source you are using ? ( sound card ? IPOD ? Mp3 ? Cassette player ? )

Does hZ in electricity matter for this kind of thing? (hZ or Hertz, is electricity flowing through a wire, at all times, not sure about AC, the electricity is off for 60 times a second and on for 60 times a second. I guess AC is a bit slower than that to consider it AC.)

I am assumming you are from North America ( USA ? Canada ? ) AC is Alternating Current A sound signal is also AC. Just the frequency is different. ( about 20 Hz to 15 000 Hz ) Correct me if I am wrong

Is there anything I have to change in schematic #3? Also, if I use a resistor of different resistance, will it decrease performance?

Sorry for confusing, actually 10 k is "optimum" value for #2. Just read data sheet again for zener, and all looks cool with leakage current 10 uA.
You don't have to change anything, but if you do, please, be advised that higher value for resistor in series with diode will attenuate input signal in #3.

@Techone I am using my phone for audio output in mp3 format.

@Magician I realize now that AC has differing frequencies, and I guess DC is just 60Hz.

and I guess DC is just 60Hz.

Guess again. Or do some research.

AC is alternating current. The frequency that it alternates at is important.

DC is direct current. Its frequency is infinite.

DC is constant current, or frequency = 0.
AC is alternating current with any frequency, except 0.
Audio signal usually considered to be AC with frequencies between 20 Hz - 20 kHz

Its frequency is infinite.

Or even zero.

@wally_z

The audio signal from the phone need a DC level going into the analog pin. ok

The top is a sine wave at 0 V line.

The bottom is a sine wave "running" at a DC line of 2.5 V. You need a voltage divider. 47 K // 47 K should be fine.

@wally_z

And the code. Well from the examples files... here a LED graph display example. It use the map() function. You program did not include one. I hope you understand. Make sure the audio signal is at proper level into the analog pin, it should be fine. I just hope your Aduino is still working.

/*
  LED bar graph
 
  Turns on a series of LEDs based on the value of an analog sensor.
  This is a simple way to make a bar graph display. Though this graph
  uses 10 LEDs, you can use any number by changing the LED count
  and the pins in the array.
  
  This method can be used to control any series of digital outputs that
  depends on an analog input.
 
  The circuit:
   * LEDs from pins 2 through 11 to ground
 
 created 4 Sep 2010
 by Tom Igoe 

 This example code is in the public domain.
 
 http://www.arduino.cc/en/Tutorial/BarGraph
 */


// these constants won't change:
const int analogPin = A0;   // the pin that the potentiometer is attached to
const int ledCount = 10;    // the number of LEDs in the bar graph

int ledPins[] = { 
  2, 3, 4, 5, 6, 7,8,9,10,11 };   // an array of pin numbers to which LEDs are attached


void setup() {
  // loop over the pin array and set them all to output:
  for (int thisLed = 0; thisLed < ledCount; thisLed++) {
    pinMode(ledPins[thisLed], OUTPUT); 
  }
}

void loop() {
  // read the potentiometer:
  int sensorReading = analogRead(analogPin);
  // map the result to a range from 0 to the number of LEDs:
  int ledLevel = map(sensorReading, 0, 1023, 0, ledCount);

  // loop over the LED array:
  for (int thisLed = 0; thisLed < ledCount; thisLed++) {
    // if the array element's index is less than ledLevel,
    // turn the pin for this element on:
    if (thisLed < ledLevel) {
      digitalWrite(ledPins[thisLed], HIGH);
    } 
    // turn off all pins higher than the ledLevel:
    else {
      digitalWrite(ledPins[thisLed], LOW); 
    }
  }
}