Receiving audio input from hifi system for vu meter

This is my first time doing this type of project and completely new to Arduino. I’m feeling i’m out of my depth!

I have successfully made a stereo VU Meter using WS2812 LED strips which I am delighted with. On set up and testing it was all set up using the audio 3.5 jack from my ipad. The lights work as planned. However I want to have the audio input coming directly from my hifi separates system. I bought myself a small headphone amplifier to take the audio from so i’m not relying on the headphone jack from my main amplifier (doing this switches off my speakers).

My issue is that when connected to either my AV amplifier or headphone amplifier the leds just illuminate fully and no longer work. I guessing this is due to the amplifiers outputting 2v.

I am looking for a simple fix to get audio signals from my amp to my Arduino Mega and hoping some of you guys can help? A simple plug and play option would be ideal if available. I have the option of using other types of audio outputs from my AV amp like optical or analog too.

Any help would be very much appreciated for the first timer!

Your post contains too little information to say anything useful. We'll need at least a schematic of your setup and the code you're using.

Why the headphone amplifier? Why not just use a line-level output of the amplifier or audio source?

"2V" is meaningless when talking about AC voltages. 2V RMS will damage your Arduino, 2Vpp or 2Vp is fine (if biased correctly).

Pieter

PieterP:
Your post contains too little information to say anything useful. We'll need at least a schematic of your setup and the code you're using.

#include <FastLED.h>

#define LED_PIN_LEFT     3
#define LED_PIN_RIGHT     4
#define NUM_LEDS    60
#define CHIPSET     WS2811
#define COLOR_ORDER GRB
CRGBArray<NUM_LEDS> ledsLeft;
CRGBArray<NUM_LEDS> ledsRight;

#define BRIGHTNESS  32

int leftChannel = 1; //analog pin
int rightChannel = 2; //analog pin

int volume = 30; //0 to 1023 - high value = lower volume
int addLedsConstant = 4 ; //how fast are LEDS added to bar
int removeLedsTimeConstant = 4; //how fast are LEDS removed from bar
int middleColorLED = 45;
int combineChannels = false; //if true channels are combined and input is only LEFT channel

int numLedsToLightLeft;
int numLedsToLightRight;

long lastRefreshTime1;
long lastRefreshTime2;

void setup() {
 FastLED.addLeds<CHIPSET, LED_PIN_LEFT, COLOR_ORDER>(ledsLeft, NUM_LEDS).setCorrection( TypicalSMD5050 );
 FastLED.setBrightness(BRIGHTNESS);
 FastLED.addLeds<CHIPSET, LED_PIN_RIGHT, COLOR_ORDER>(ledsRight, NUM_LEDS).setCorrection( TypicalSMD5050 );
 FastLED.setBrightness(BRIGHTNESS);
}

void loop() {
 int ledsToLightLeft = map(analogRead(leftChannel), 0, volume, 0, NUM_LEDS);
 int ledsToLightRight = map(analogRead(rightChannel), 0, volume, 0, NUM_LEDS);
 
 if (combineChannels) {
   ledsToLightRight = ledsToLightLeft;
 }
 
 if (ledsToLightLeft > numLedsToLightLeft) {
   numLedsToLightLeft += addLedsConstant;
 } else if (ledsToLightLeft < numLedsToLightLeft) {
   if(millis() - lastRefreshTime1 >= removeLedsTimeConstant) {
     lastRefreshTime1 += removeLedsTimeConstant;
     numLedsToLightLeft -= 1;
   }
 }
     
 if (numLedsToLightLeft < 1) {
   numLedsToLightLeft = 0;
 }
 if (numLedsToLightLeft > NUM_LEDS) {
   numLedsToLightLeft = NUM_LEDS;
 }

if (ledsToLightRight > numLedsToLightRight) {
   numLedsToLightRight += addLedsConstant;
 } else if (ledsToLightRight < numLedsToLightRight) {
   if(millis() - lastRefreshTime2 >= removeLedsTimeConstant) {
     lastRefreshTime2 += removeLedsTimeConstant;
     numLedsToLightRight -= 1;
   }
 }
     
 if (numLedsToLightRight < 1) {
   numLedsToLightRight = 0;
 }
 if (numLedsToLightRight > NUM_LEDS) {
   numLedsToLightRight = NUM_LEDS;
 }

for(int led = 0; led < numLedsToLightLeft; led++) {
   if (led < middleColorLED) {
     ledsLeft[led] = CRGB(map(led, 0, middleColorLED - 1, 0, 255) ,255,0);
   } else {
     ledsLeft[led] = CRGB(255, map(led, middleColorLED, NUM_LEDS, 255, 0),0);
   }
 }
 for(int led = NUM_LEDS; led >= numLedsToLightLeft; led--) {
   ledsLeft[led] = CRGB(0, 0, 0);
 }

for(int led = 0; led < numLedsToLightRight; led++) {
   if (led < middleColorLED) {
     ledsRight[led] = CRGB(map(led, 0, middleColorLED - 1, 0, 255) ,255,0);
   } else {
     ledsRight[led] = CRGB(255, map(led, middleColorLED, NUM_LEDS, 255, 0),0);
   }
 }
 for(int led = NUM_LEDS; led >= numLedsToLightRight; led--) {
   ledsRight[led] = CRGB(0, 0, 0);
 }
 
 FastLED.show();
}




NOT MY SCHEMATIC DRAWING!!! lol


Why the headphone amplifier? Why not just use a line-level output of the amplifier or audio source?

I was using it to so i could set the gain separately, however I am happy to ditch it if you think that would be best.

"2V" is meaningless when talking about AC voltages. 2V RMS will damage your Arduino, 2Vpp or 2Vp is fine (if biased correctly).

Pieter

Please read the forum rules about how to properly post code, and edit your previous post.

I don't know who Electoni is, but he clearly had no idea what he was doing when he drew that schematic. The Arduino's ADC can only measure positive voltages. Applying an unbiased AC voltage will damage it. By connecting the audio output directly to the Arduino, you apply negative values to the ADC, and the clamping diodes won't help you because the output impedance of the headphone output is way too low.

In your code, you directly map the input voltage to the number of LEDs, which is not correct, even ignoring the problems with the hardware. The voltage you're reading is AC, the instantaneous value you read using analogRead is not the actual amplitude of the signal. You'll need a rectifier and a low-pass filter or an envelope follower.

porschecraig:
I was using it to so i could set the gain separately

There's no reason for that, a simple potentiometer or a scaling factor in your code would have done the trick.


Some ways of handling the AC audio signal -

  1. The most common solution is to bias the input at 2.5V. The circuit (2 equal-value resistors and a capacitor) is attached to the bottom of [u]this post[/u]. With the bias circuit silence will read about 512 so typically you'd subtract that out in software.

  2. A [u]protection circuit[/u] can protect against negative voltages and/or excess positive voltages. With line-level signals the series resistor should be increased to 10K. With headphone or speaker connections, 100 Ohms is OK.

  3. A [u]peak detector[/u] (AKA voltage follower) will "ignore" the negative half of the signal. A peak detector has the advantage of putting-out a varying DC voltage so you you don't have to worry about "sampling" the waveform.* You can read the "loudness" at around 10 times per second instead of sampling the waveform thousands of times per second.

A peak detector will work best (cover the full 0-5V range) if it's powered by +/-12V (or +/-9V, etc.).
And then you should have an over-voltage protection circuit at the peak detector output in case it goes over 5V.


If you connect speaker-outputs -

You should have an over-voltage protection circuit. You also may need a [u]voltage divider[/u] depending on amplifier power. (That's just one resistor more added to the protection circuit.)

Check your amplifier's speaker outputs with an Ohmmeter to make sure the "negative connection"-output is actually ground. (Or make sure both negative outputs are "shorted" together inside the amplifier.) If your amplifier has a bridge-output (not common in home stereos) you can damage it by connecting the "negative" left & right speaker connections together, or by connecting them to ground.

it was all set up using the audio 3.5 jack from my ipad. The lights work as planned...

...My issue is that when connected to either my AV amplifier or headphone amplifier the leds just illuminate fully and no longer work. I guessing this is due to the amplifiers outputting 2v.

Run the [u]Analog Read Serial Code[/u] to see what different readings you're getting with the different connections. (Take-out the delay.)

  • The audio signal is a wave where each cycle has a positive peak, a negative peak, and it crosses-through zero twice per cycle. That means you get "random looking" readings and you need to find the peak, or take the average of the positive values, or the average of the absolute values, or the RMS etc.