LED Music visualizer

Hi All,
I have an issue with my project, that is driving me crazy.

I am making Music reactive LED visualizer (LED strip), following steps from GitHUB: GitHub - justcallmekoko/Arduino-FastLED-Music-Visualizer: An Arduino based music visualizer using the FastLED library and a strip of individually addressable LEDs, with few adaptations. First one is parallel wiring of AUX inputs/outputs, as I want to have sound also directed to speakers (I guess that this is not an issue), second one is putting resistor in between of A0 wire and AUX wires (that is the different from original schematics). All other things stays same - I didn't changed a code (just when I was checking and adapting code with NUM_LEDS).

The issue is, that when I plug in my phone with AUX cable, only first 10 LEDs are lit and reacting on music, while, when it is in Idle mode (Rainbow cycle) all of the LED's are lit. I am using parallel wiring for LED's and Arduino with 5V adapter.

On this URL, you can find pictures of project:

Do you have any ideas where can I have and issue?

Thank you all for helping me,
Stay safe and healthy
Ziga

Ziga, that circuit will damage the Arduino. The headphone output is an AC signal, with positive and negative voltages. The Arduino's analog inputs (or any other inputs) will be damaged by the negative voltages.

Hi Paul,
Thanks a lot for your input, so this is the first issue that I need to work it on (probably this is also why author worked with Sparkfun Spectrum), but despite that, I am still afraid that it will not solve my issue (as I saw in some video, it worked even with AC signal). BTW, due to small voltage on the output, I am afraid that it would disturb signal - do you have any idea what is the easiest way to convert it (I am still new at all of this and am still learning).

Thanks,
Ziga

I think what you need is a circuit called an envelope follower. This turns the AC audio signal into a positive voltage representing the loudness of the sound.

Hi Paul,
Thanks for idea, I have now installed "envelope", but the issue still exist. When I plug in phone, all LEDs get dark, it "helps" only when I take away wire from envelope to GND, but that causes that LEDs goes to rainbow circle.
Do you have any further ideas about this issue?
Thank you,
All the best
Ziga

Hi Ziga. I'm sure we can think of some ideas. Please post your latest code and your schematic (hand drawn is ok), and some pictures of the circuit could be usefull for checking also, if they are bright and clear and we can see where each wire connects. Please read the forum guide and post those things as described in the guide.

Hi Paul,
The first mistake I found and eliminate it (I had wrong resistor installed), so now it seems, that it reads signal from phone, but it just don't react to it - like the signal is same for all time.
Nevertheless, I am sending you schematic (sorry for my bad drawing) and latest code, which is uploaded to Arduino Uno.

#include <FastLED.h>

// LED LIGHTING SETUP
#define LED_PIN     6
#define NUM_LEDS    400
#define BRIGHTNESS  64
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];

#define UPDATES_PER_SECOND 400

// AUDIO INPUT SETUP
int audio = A0;

// STANDARD VISUALIZER VARIABLES
int loop_max = 0;
int k = 255; // COLOR WHEEL POSITION
int decay = 0; // HOW MANY MS BEFORE ONE LIGHT DECAY
int decay_check = 0;
long pre_react = 0; // NEW SPIKE CONVERSION
long react = 0; // NUMBER OF LEDs BEING LIT
long post_react = 0; // OLD SPIKE CONVERSION

// RAINBOW WAVE SETTINGS
int wheel_speed = 3;

void setup()
{
  // LED LIGHTING SETUP
  delay( 3000 ); // power-up safety delay
  FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  FastLED.setBrightness(  BRIGHTNESS );

  // CLEAR LEDS
  for (int i = 0; i < NUM_LEDS; i++)
    leds[i] = CRGB(0, 0, 0);
  FastLED.show();

  // SERIAL AND INPUT SETUP
  Serial.begin(115200);
  pinMode(audio, INPUT);
  Serial.println("\nListening...");
}

CRGB Scroll(int pos) {
  CRGB color (0,0,0);
  if(pos < 85) {
    color.g = 0;
    color.r = ((float)pos / 85.0f) * 255.0f;
    color.b = 255 - color.r;
  } else if(pos < 170) {
    color.g = ((float)(pos - 85) / 85.0f) * 255.0f;
    color.r = 255 - color.g;
    color.b = 0;
  } else if(pos < 256) {
    color.b = ((float)(pos - 170) / 85.0f) * 255.0f;
    color.g = 255 - color.b;
    color.r = 1;
  }
  return color;
}

// FUNCTION TO GET AND SET COLOR
// THE ORIGINAL FUNCTION WENT BACKWARDS
// THE MODIFIED FUNCTION SENDS WAVES OUT FROM FIRST LED
// https://github.com/NeverPlayLegit/Rainbow-Fader-FastLED/blob/master/rainbow.ino
void rainbow()
{
  for(int i = NUM_LEDS - 1; i >= 0; i--) {
    if (i < react)
      leds[i] = Scroll((i * 256 / 50 + k) % 256);
    else
      leds[i] = CRGB(0, 0, 0);      
  }
  FastLED.show(); 
}

void loop()
{
  int audio_input = analogRead(audio), x4;  // ADD x2 HERE FOR MORE SENSITIVITY  

  if (audio_input > 0)
  {
    pre_react = ((long)NUM_LEDS * (long)audio_input) / 1023L; // TRANSLATE AUDIO LEVEL TO NUMBER OF LEDs

    if (pre_react > react) // ONLY ADJUST LEVEL OF LED IF LEVEL HIGHER THAN CURRENT LEVEL
      react = pre_react;

    Serial.print(audio_input);
    Serial.print(" -> ");
    Serial.println(pre_react);
  }

  rainbow(); // APPLY COLOR

  k = k - wheel_speed; // SPEED OF COLOR WHEEL
  if (k < 0) // RESET COLOR WHEEL
    k = 255;

  // REMOVE LEDs
  decay_check++;
  if (decay_check > decay)
  {
    decay_check = 0;
    if (react > 0)
      react--;
  }
  //delay(1);
}

Schematics and some pictures are in attachments
Thank you very much for helping me :slight_smile:
Best, Žiga

Your schematic is missing some labels. What are the two components with 3 pins each at the bottom? Where is the audio connection? Also there is an error, the cap and resistor in the envelope circuit have no ground connection.

Your pictures are not clear, they are too heavily compressed I think. I cannot see the signal diode. I can see an led that is not shown in your schematic. If you are using an led in place of the signal diode, that will not work.

Why are there 5 wires to the headphone socket? Only 3 should be required.

Do you know how to use a breadboard, which holes are connected inside? Some components and wires are plugged in but connected to nothing! For example, one end of the resistor.

What are the two components with 3 pins each at the bottom?

I suspect they are the audio connectors. You seem to have all the outputs shorted together. That is not a good thing to do.

Hi, Paul, Mike,
The two connectors are Audio In and Out jacks, so signal from device can go to Arduino and to speaker.
Below please find better photos and updated schematics.
Also thanks for noticing miss-wired resistor - I have it now connected, but as soon as I did such thing, all LEDs shut down - even if phone was pluged in or not.
Redarding the diode - I used LED diode, as I don't have regular one for 5V...
Hope the pictures are more clear now :slight_smile:

Thank you very much :smiley:

Yes, the pictures are clearer now, and the schematic is better. The schematic even makes it quite clear that you have incorrectly used a led where a signal diode is required.

You also seem to be shorting together pins 2 and 3 of the audio. That will damage your audio device. At the very least you should have a 22K resistor in each lead going to the anode of the diode. Note you will need at least 0.7V peak to peak audio signal to get anything out of this circuit. The decay of the threshold is controlled by the size of the resistor across that capacitor.

I can’t quite read the value of capacitor you are using but it seems to be 22 pF, which is out by four orders of magnitude. Your resistor seems to be 100 ohm not 100,000 ohm.

Hi guys,

So, I changed LED diode to signal diode, but the signal still doesn't come from phone to LED's., But there is a reaction, when I touch jack with hands or similar (same as you hear noise in speaker) I guess that I should build amplifier, as the issue is really in voltage, as Grumpy_Mike posted.
Grumpy_Mike, one additional question - why would parallely wired input and output of audio damage audio device. Is this due to current?

Thank you very much

why would parallely wired input and output of audio damage audio device.

It is not the sockets it is the fact you have connected two outputs together the left and right audio.

I'm not sure what this line is doing, kinda surprisd it compiles:

int audio_input = analogRead(audio), x4;  // ADD x2 HERE FOR MORE SENSITIVITY

Suggest you change this to

int audio_input = analogRead(audio);  // ADD x2 HERE FOR MORE SENSITIVITY
Serial.println(audio_input);

What values do you see on serial monitor?

Hi guys,

I corrected code, and I think that it is better, but my guess is, that the reading are still too weak, to see the result. I am thinking on installing also an amplifier before envelope follower. What do you think of this one in picture - would it be enough?
Regarding wireing of inputs - I noticed that one wire is enough also for sound quality (when did first trials, only with both was OK).
Thanks :slight_smile:

Capture.JPG

Capture.JPG

That circuit has a voltage gain of exactly one. So it wouldn’t help.

I guess that you suggest than, that I use 12V power supply for LED strip and amplifier and 5V for circuit powering?

Hi Ziga, as you are no longer responding to my questions, I will wish you luck with your project.

I guess that you suggest than, that I use 12V power supply for LED strip and amplifier and 5V for circuit powering

No, do you want to guess again or do you want me to tell you?