Why does PWM creates noise?

I'm using just the audio input part of this diagram to A0 so the arduino can read the signal of my guitar and make the led strip blink.http://interface.khm.de/index.php/lab/experiments/arduino-realtime-audio-processing/ But instead of using only one audio jack input I'm using two in parallel to send part of the signal to my amplifier and some to arduino. The problem is when I switch to a PWM sketch, noise gets to the amplifier and disappear when the value reaches zero.

PWN is creating 5V rising & falling edges 500 times a seconds - wires connected to the PWM pins act like antennas. Need to control your emissions, put a grounded shield over wires, grounded at one end, with as little exposed wire as possible.

How is this all powered? - you really need to keep the Arduino's supply separate from the LED strips (where all the current switching is), and pay attention to grounding - separate ground wires out to the audio input and the PWM output might make a difference.

Especially if both "Grounds" were connected to the most negative point on the board... because all the separate currents flow through the 'ground' and all conductors have Some" resistance... so If your high gain amp input shield were connected between the high current return (ground) wire from the LEDs it would be 'seeing' that part of the LED current as a voltage developed across the "Grounds" and it is entirely possible that the input lead is at a lower potential than the points used as ground (Multiple ground return path's)... Thus there is a voltage across the amp input. This is what in all likelihood the effect you are seeing. It is also one of the reasons why analog readings are difficult to make sometimes with an Arduino, accurately.

Bob

MarkT:
How is this all powered? - you really need to keep the Arduino’s supply separate from the LED strips (where all the current switching is), and pay attention to grounding - separate ground wires out to the audio input and the PWM output might make a difference.

I think that’s a good idea too, I had the same problem with effect pedals, most of them are connected in my main power supply station but some need to be with their own power supply because they create noise too.
Right now I have the Arduino and the strip running with the same 12V power supply.

Normally I'd say isolate them... but unless your on board regulator (Arduino) is running hot... Just make sure of the grounds... try to use a star topology where Every Ground goes to [u]one[/u] Common Point. Never Never daisy chain grounds or the Positive Supply runs. All wires including PC boards have Both resistance and worse inductance both of which will increase as your project changes and both of which are 1/2 of the primary offenders for producing noise. Obviously the other half is the various supply voltages however it is Very Common to think that ground is Ground. Short wiring and plenty of bypass caps... make the job work well.

Bob

I think you can change the prescaler so that the modulation is at a higher frequency. The noise you hear is probably harmonics from the square wave. Just shove it out of human hearing range.

Great Idea, just move them out of the passband of your amp so they don’t get amplified. Even though you can’t hear it doesn’t mean that the amp can’t amp it and that is wasted power and a possible source of distortion if any of the amp sources has any power in that range they might mix and cause noise.

Bob

Great Idea, ...

Or not?

However audio amplifiers probably don't amplify in the megaherz range.

However that was just a suggestion. If you can eliminate the noise, all the better.