Pages: [1]   Go Down
Author Topic: Audio levels go up when a relay is turned on  (Read 532 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Phoenix, Arizona USA
Offline Offline
Faraday Member
**
Karma: 36
Posts: 5519
Where's the beer?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

Maine
Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
You blocked me on facebook and now youre going to die!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

« Last Edit: March 21, 2013, 08:24:37 am by conradin » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16548
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Shannon Member
****
Karma: 162
Posts: 10496
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

[ I won't respond to messages, use the forum please ]

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
        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?
Logged

Pages: [1]   Go Up
Jump to: