Problem with mic amplifier + led

Hello,

I have an amplifier with an LM386N-1 and an electret microphone that I’m using with my Arduino UNO.

I’m attaching a picture of the breadboard circuit and the Arduino. Unfortunately I can’t find the schematic I based this off, since I built it from an online guide a long time ago and don’t have the link anymore.

I’m plotting the input and it seems ok.

As soon as I add a led + resistor connected to other Arduino pins, I start getting interference in the amplifier.

I know for certain this is not RF interference, as I’ve tried running the led in one arduino, and the amplifier in another arduino right next to each other, and the problem went away immediately.

I realize the info is pretty thin, but I was hoping to produce more pictures and/or details as required.

Thanks.

It would be helpful if you’d draw-up a schematic from what you have.

I’m plotting the input and it seems ok.

What does that mean? You’re getting readings that seem to correlate with the sound? Are you using the serial monitor?

As soon as I add a led + resistor connected to other Arduino pins, I start getting interference in the amplifier.

What does that mean? The readings get bad? You’re not changing the software, right? You’re just adding the LED & resistor?

What’s the resistor value, and are you sure about the resistor value? An LED shouldn’t affect the Arduino’s operation unless you leave-out the resistor or unless the current-limiting value resistor is too low? The resistor is in series with the LED, right?

BTW - The LM386 isn’t a designed as a microphone preamp (although it might be usable as one) and I can’t tell if you’ve got power to the electret mic.

I realize the info is pretty thin, but I was hoping to produce more pictures and/or details as required.

OK so please post the schematic, a photo of a mess of wires is not helpful.

Unfortunately I can’t find the schematic I based this off, since I built it from an online guide a long time ago and don’t have the link anymore.

So trace the circuit on your breadboard, draw it on a piece of paper and post a photo of the paper.

How is the LED wired and how is it controlled. You need to post your code so we can see.
Please read this:- How to use this forum to see how to post it correctly using the </> icon.

As soon as I add a led + resistor connected to other Arduino pins, I start getting interference in the amplifier.

Sounds like you have little or no decoupling in that audio circuit. Decoupling
It also sounds like you may be running the LED with PWM and that will cause interference. A good layout and good decoupling will solve that.

DVDdoug:
It would be helpful if you'd draw-up a schematic from what you have.

Just found the original schematic.

This is the guide I used for the preAmp.

What does that mean? You're getting readings that seem to correlate with the sound? Are you using the serial monitor?

I get readings that seem to correlate with the sound. I'm using the serial plotter to see the waves.

It responds to noises in the way I'd expect it to. Silence -> small waves, noise -> taller waves.

What does that mean? The readings get bad? You're not changing the software, right? You're just adding the LED & resistor?

I always use the same Arduino compiler (downloaded from this site) for all my testing and serial inspection. I never use another software or visualizer.

There's clearly noise as the waves start going crazy the moment I plug the led (the led is trying to change it's color and luminosity continuously based on the sound input from the preAmp).

What's the resistor value, and are you sure about the resistor value? An LED shouldn't affect the Arduino's operation unless you leave-out the resistor or unless the current-limiting value resistor is too low? The resistor is in series with the LED, right?

I'll let you decide since I am pretty sure I am making a mistake somewhere. To be honest I wonder if the LED being RGB means my resistor calculation is wrong.

The LED is rated as 3.0-3.5v, 20mA. They're RGB leds (common anode).

The resistance is 100 Ohm and it's connected to the common anode.

The calculation I used was: (5v from the arduino - 3v forward voltage for the led) / 0.02A = 100 Ohm.

BTW - The LM386 isn't a designed as a microphone preamp (although it might be usable as one) and I can't tell if you've got power to the electret mic.

I can provide better pictures if the schematic linked above doesn't suffice. Let me know.

Thanks a lot for your time!

Grumpy_Mike:
OK so please post the schematic, a photo of a mess of wires is not helpful. So trace the circuit on your breadboard, draw it on a piece of paper and post a photo of the paper.

I just posted the schematic I based it off. Can you please let me know if that’s enough, or if you want me to draw the schematic based on what I have?

I don’t mind doing it but if the schematic above does suffice, so much better.

How is the LED wired and how is it controlled. You need to post your code so we can see.
Please read this:- How to use this forum to see how to post it correctly using the </> icon.
Sounds like you have little or no decoupling in that audio circuit. Decoupling
It also sounds like you may be running the LED with PWM and that will cause interference. A good layout and good decoupling will solve that.

Thanks, I’ll take some time to read these before moving ahead.

I’m providing here my code as requested. It’s just testing code, the idea is just to show some sort of reaction on the led based on the input.

#define audioPin A0
#define redPin 11
#define greenPin 10
#define bluePin 9
#define ledAnodePin 13

static int pinCounter = 0;
static int changeColorDelay = 0;

void setup() {
  Serial.begin(9600);
  
  pinMode(audioPin, INPUT);
  pinMode(ledAnodePin, OUTPUT);
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);

  analogWrite(ledAnodePin, 255);
  analogWrite(redPin, 255);
  analogWrite(greenPin, 255);
  analogWrite(bluePin, 255);
}

void loop() {

  int value = analogRead(audioPin);

  double lightValue = ((double) abs(value - 512)) / 512;
  double newValue = 0;
  
  if (lightValue > 0) {
    newValue = 255 * (1 / lightValue);
  }

  if (pinCounter == 0) {
    analogWrite(redPin, newValue);
    analogWrite(greenPin, 255);
    analogWrite(bluePin, 255);
  } else if (pinCounter == 1) {
    analogWrite(redPin, 255);
    analogWrite(greenPin, newValue);
    analogWrite(bluePin, 255);
  } else if (pinCounter == 2) {
    analogWrite(redPin, 255);
    analogWrite(greenPin, 255);
    analogWrite(bluePin, newValue);
  }

  //Serial.print("Valor: ");
  Serial.println(value);
  delay(10);
  changeColorDelay += 10;

  if (changeColorDelay == 1000) {

    changeColorDelay = 0;
    pinCounter++;

    if (pinCounter == 3) {
      pinCounter = 0;
    }
  }
}

EDIT: Sorry while reading #15 from the forum etiquette I just realized I must provide my own schematic. Please allow me some time to comply.

Thanks everyone for the help.

I just posted the schematic I based it off. Can you please let me know if that’s enough, or if you want me to draw the schematic based on what I have?

It is always vital to post the schematic of what you have, who knows what changes you have made.
As you are having problems with the LED and amplifier interacting we need to see these as well as the Arduino on the schematic.

The resistance is 100 Ohm and it’s connected to the common anode.

This is not your problem but this is wrong. You want a resistor in the cathode of each element. The way you have it there are some colours and combinations you will not get. I would put a 220R in each cathode.

The PWM noise (now that we know you are using PWM) is probably getting into the amplifier though the power supply.

So, tell us about your power supply. Are you using a 5Vor 12V wall wart? USB power?

As an experiment, you can try a separate power supply for the amplifier (if you have one) or try a 4.5V battery pack. Or try a separate 5V regulator if you're running from a 12V power supply. (It's not unusual that a preamp will have it's own regulator.) Or, try a "big old" capacitor (1000uF or more) across the power supply to improve the filtering

....I've got a couple more suggestions for your preamp circuit, but later... I gotta' get back to work.

Having a star ground system will help minimise PWM noise. That is the ground for the amplifier and the ground for the LED all meet at the one point. That is they are not chained.

Ok... Your amplifier...

The 220uF DC blocking capacitor means you don't have a DC reference for the Arduino analog input and the input will "float" to an undefined voltage. If you don't already have one, you need a resistor to ground on the Arduino's input (maybe 10K).

But... The DC-blocking capacitor also means that the amplifier's AC output voltage swings negative. You want that with a normal audio amplifier but negative voltages can damage your Arduino. If you remove that capacitor (replace it with a short) you'll solve both problems, but the input will be biased at about 2.5V and the ADC should read about 512 with silence, so you might have to subtract-out the bias in software.

Grumpy_Mike:
It is always vital to post the schematic of what you have, who knows what changes you have made.
As you are having problems with the LED and amplifier interacting we need to see these as well as the Arduino on the schematic.

Thank you for the patience, and sorry for not reading as carefully as I should’ve.

I’ve taken the time to bring my board into a schematic of my own. It IS based off the design I posted but slightly different (there’s no speaker or its capacitor).

I’ve attached the schematic to this message.

Grumpy_Mike:
This is not your problem but this is wrong. You want a resistor in the cathode of each element. The way you have it there are some colours and combinations you will not get. I would put a 220R in each cathode.

I’ve taken the time to fix my small RGB LED board to add the 250R resistors at each cathode, and remove the resistor I had at the common anode.

It’s working nicely as far as I can tell. I hope those values are good? (I didn’t have a good assortment of resistors to combine 220R).

DVDdoug:
The PWM noise (now that we know you are using PWM) is probably getting into the amplifier though the power supply.

So, tell us about your power supply. Are you using a 5Vor 12V wall wart? USB power?

As an experiment, you can try a separate power supply for the amplifier (if you have one) or try a 4.5V battery pack. Or try a separate 5V regulator if you’re running from a 12V power supply. (It’s not unusual that a preamp will have it’s own regulator.) Or, try a “big old” capacitor (1000uF or more) across the power supply to improve the filtering

…I’ve got a couple more suggestions for your preamp circuit, but later… I gotta’ get back to work.

USB power at first.

I also tried hooking up an external battery (12v regulated down to 5v) only for the amplifier, and hooking up the ground terminal to the Arduino’s, but that didn’t change the result. I’m not even sure if hooking up the battery’s ground to the arduino’s ground was a safe thing to do.

This was advised to me by an electronic engineer I know. He’s not available enough to count on his help unfortunately.

DVDdoug:
Ok… Your amplifier…

The 220uF DC blocking capacitor means you don’t have a DC reference for the Arduino analog input and the input will “float” to an undefined voltage. If you don’t already have one, you need a resistor to ground on the Arduino’s input (maybe 10K).

But… The DC-blocking capacitor also means that the amplifier’s AC output voltage swings negative. You want that with a normal audio amplifier but negative voltages can damage your Arduino. If you remove that capacitor (replace it with a short) you’ll solve both problems, but the input will be biased at about 2.5V and the ADC should read about 512 with silence, so you might have to subtract-out the bias in software.

Sorry about posting the schematic I based my amp off. I’ve now posted a schematic made by myself - the 220uF capacitor isn’t there. Again, sorry.

EDIT: fixed an error in the schematic

I’m not even sure if hooking up the battery’s ground to the arduino’s ground was a safe thing to do.

Not only is it safe, it will not work if you don’t do it.

The new schematic doesn’t show the LEDs or the Arduino.
A resistor value of 250R is fine but I have never seen one of that value. The actual value is not critical anything over 220R will be fine.

Why two capacitors in seriese on the output of the amplifier? Is that supposed to be some sort of filter? If it is it will not work as a filter wired like that.

Grumpy_Mike:
Not only is it safe, it will not work if you don’t do it.

The reason I was doubtful is that the ON led on the Arduino would light up when connecting the battery’s negative terminal to the Arduino UNO’s ground pin, even though the USB wasn’t connected. It looked very strange to me.

Grumpy_Mike:
The new schematic doesn’t show the LEDs or the Arduino.
A resistor value of 250R is fine but I have never seen one of that value. The actual value is not critical anything over 220R will be fine.

I’ve added the LED circuit in the schematic attached to this reply. The reason I went for 250R is that the closest resistors I had were 100R and 150R, so I put them in series with each cathode of the LED.

I couldn’t find an Arduino UNO shield in my Proteus installation, but I’ve listed the exact pin names I’m hooking my circuits to. Is that’s ok?

There’s nothing else connected to the Arduino UNO (other than the USB connector) when running my tests.

Grumpy_Mike:
Why two capacitors in seriese on the output of the amplifier? Is that supposed to be some sort of filter? If it is it will not work as a filter wired like that.

I didn’t have a single 47nF capacitor as in the original schematic I posted (C4 in the schematic I posted initially). I put two 0.1uF capacitors in series to achieve 50nF.

The guide I used for this schematic mentions this capacitor is a Boucherot Cell. The Wikipedia article I found on Boucherot Cells is not very clear to me to be honest: my best interpretation of it is that it removes high frequency noise, but it also mentions it’s mostly for loudspeakers so I’m not sure if I should keep it.

EDIT: attached the missing schematic.

The reason I was doubtful is that the ON led on the Arduino would light up when connecting the battery's negative terminal to the Arduino UNO's ground pin, even though the USB wasn't connected. It looked very strange to me.

That sounds like parasitic powering. It is nothing to do with connecting the ground, it is to do with putting an input into an unpowered device. You must never do this as it can damage your Arduino. This applies to all electronics devices not just an Arduino.

The pin 13 powering the LEDs has to provide the current for three LEDs which it can but just about.

C4 should be 10uF or bigger and C1 should be of the ceramic type.

The LM386 is not a suitable amplifier for this project. It is an audio amplifier, designed to be connected to a speaker.

Grumpy_Mike:
That sounds like parasitic powering. It is nothing to do with connecting the ground, it is to do with putting an input into an unpowered device. You must never do this as it can damage your Arduino. This applies to all electronics devices not just an Arduino.

Thanks for this valuable info.

So if I understand correctly, would this be a suitable connection order?

  • Connect the arduino to power
  • Connect the grounds between arduino and battery
  • Connect the amp to power from the battery
  • Connect the amp to the arduino pins

Grumpy_Mike:
The pin 13 powering the LEDs has to provide the current for three LEDs which it can but just about.

I hadn't considered this. Shall I use a transitor + external power source instead, or is there a better alternative?

Grumpy_Mike:
C4 should be 10uF or bigger and C1 should be of the ceramic type.

Thanks... I'm not sure if to test this or just go for a LM358 (read below).

Grumpy_Mike:
The LM386 is not a suitable amplifier for this project. It is an audio amplifier, designed to be connected to a speaker.

If I understand correctly from the info I'm finding online, an Op Amp would be what I need. Does LM358 sound like a good alternative if I wanted to start over?

So if I understand correctly, would this be a suitable connection order?..........

No it should be:-

  1. Connect the grounds between arduino and battery
  2. Connect the amp to the arduino pins
  3. Connect the arduino to power
  4. Connect the amp to power from the battery

Does LM358 sound like a good alternative if I wanted to start over?

Well it is a 5V minimum supply so it is not too good at that with regards rail to rail operation. I have used the MCP601 which I think is a good compromise between price and performance.

I hadn't considered this. Shall I use a transitor + external power source instead,

Just a transistor and the 5V pin from the Arduino.

I'm not sure if to test this or just go for a LM358

You will need this on the supply rails no matter what op-amp you choose.