DC bias issues with LM386 and LED cube ANALOG INPUT

Hi Guys,

I am trying to make a LED cube that responds to bass, mid, and treble freqs. I am using 3 filters for my audio and feed them into 3 analog inputs of the arduino. As an amplifier, I am using a LM386 http://www.ti.com/lit/ds/symlink/lm386.pdf

The problem is (see schematic attached):

If there is no signal present, even then my analog input reads a steady value of around 512-1023 (seen in the serial monitor). It turns out that the value corresponds to the V+ supply to the LM386 and is half of V+, ie, just like the LM386 outputs a signal in the middle of the range 0-V+, it even does it for if there is no AC signal present. As a result of this, ALL my LEDs are on at all times, for the A0 reads off the value and it is well over the threshold for just the signals.

To avoid the problem, I introduced a capacitor ( C_ac_coup ) of around 100uF to act as a AC coupling device, but sadly it does not work. I could not figure out why.

Moreover, whenever I try to connect the GND of the arduino to the GND of my function generator (connected to wall outlet), my computer disconnects the arduino from the USB port. Does anyone know why?

I tried to correct the problem using mods in the code, but failed to.

Here is the code (it just does it for the bass at the moment):

int led[6] = { 3, 4, 5}; // Assign the pins for the leds
int leftChannel = A0; // left channel input
int left, i,left1;

void setup()
{
for (i = 0; i < 3; 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)-200;
Serial.println(left);
Serial.print("\t");// uncomment to check the raw input.
*left = left / 200; // adjusts the sensitivity *
Serial.println(left);
Serial.print("\t");// 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 < 3; 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 = left; i < 3; i++) // turn off the leds above the voltage level*
* {*
_ digitalWrite(led*, LOW);
}
}
}
All I am trying to do with the code is to turn of a series of 3 columns of led depending on the strength of the signal (think of it as a volume meter of bass, etc. for each column).
Can anyone make it modifications to this code and/ or the HARDWARE to
a) take care of the DC bias
b) use a better calibration technique whereby I don't have to cardcode a calibration factor into it.
Really messed up now, guys. So any help will be appreciated.
proj.bmp (385 KB)*_

P.S. I also tried subtracting the CONSTANT amount from the readings, but the problem is: it is a NEW constant value every time!!! So that doesn't work

Perhaps, DC Restoration:
a diode -- cathode to C_as_coup neg/out, anode to Gnd.

I think I'd go with three buffer amps off the audio source and each into its LP, BP, or HP instead.

You could try putting a 100? to 1000? resistor between pin 2 and ground of your LM386. I would suspect the inverting input is floating above ground and causing an unwanted output from the LM386.