Audio levels go up when a relay is turned on

I'm using a Arduino nano for a project and have an audio mic breakout connected to A1 and a relay that is activated when A2 is turned to high. My mic is consistently giving me readings around 600, but when I turn the relay on (A2 to high) , the readings jump up to around 1500.

I've tried connecting the relay to the digital pins, but have the same problem. For some reason, I don't have any problems when using an Uno board.

Can anyone explain what is happening and how to fix it? Thanks.

I don't know the explanation, but I do know that the separate analog pins (A0-A5) all share the same ADC on the ATMega328; maybe by virtue of this "sharing", attempting to use one of the analog pins as a digital output causes a pin that's an analog input to fluctuate somehow? Have you tried controlling your relay via a regular digital I/O pin?

cr0sh:
I don't know the explanation, but I do know that the separate analog pins (A0-A5) all share the same ADC on the ATMega328; maybe by virtue of this "sharing", attempting to use one of the analog pins as a digital output causes a pin that's an analog input to fluctuate somehow? Have you tried controlling your relay via a regular digital I/O pin?

Post a schematic, I bet we can figure this out. Im having a though time figuring why youd use a relay for audio(?)
if your driving the analogue output higher than [EDIT](My bad), 40ma your almost certainly going to encounter problems.

The audio is separate from the relay. I have the mic breakout connected to 5v, Ground, and A1.

The relay is connected to 5v, Ground, and A2 (I've tried other pins as well, including digital).

In my sketch, when audio levels go past 1000 the relay is supposed to turn off, below 1000 the relay is supposed to turn on.

The problem is that when audio goes below 1000 and turns the relay on on A2, it causes the audio levels on A1 to jump up above 1500, causing the relay to turn off.

nonlinearmind:
The audio is separate from the relay. I have the mic breakout connected to 5v, Ground, and A1.

The relay is connected to 5v, Ground, and A2 (I've tried other pins as well, including digital).

In my sketch, when audio levels go past 1000 the relay is supposed to turn off, below 1000 the relay is supposed to turn on.

The problem is that when audio goes below 1000 and turns the relay on on A2, it causes the audio levels on A1 to jump up above 1500, causing the relay to turn off.

Probably a power problem because the relay may be drawing more current then any arduino output pin can safely handle. Post a link to the relay datasheet and see how much current it requires to operate.

Lefty

I don't understand "the readings jump up to around 1500."
ADC output is 0..1023

The audio readings aren't voltage. The sketch calculates the signal with this:

        long sumOfSquares = 0;
  for (int i = 0; i<numberOfSamples; i++) { //take many readings and average them
  sample = analogRead(micSensorPin); // take reading
  signal = (sample - middleValue); // work out its offset from center
  signal *= signal; // square it to make all values positive
  sumOfSquares += signal; // add to the total
  }
  
  averageReading = sumOfSquares/numberOfSamples;

To make things even stranger, when my Arduino Nano is being powered via USB from my computer, everything is fine. However, when the nano is powered via USB from a powered USB hub, it gives me the issues mentioned. It's like a day and night difference. Can anyone tell me why this is happening and how I can solve it?