Really weird problem w/ arduino input

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
bxl5138
 
Posts: 6
Joined: Wed Sep 03, 2014 3:03 pm

Really weird problem w/ arduino input

Post by bxl5138 »

Hey guys,

Quick question. I'm working with a MAX4466 mic/amp, trying to set up some audio reactive LEDs. The mic (powered by 3.3V) works fine up to a certain voltage -- 1.12, roughly. Once the mic/amp reaches this threshold, the serial monitor (displaying volts) shows something like this:

1.11
0.05
1.14
1.11
0.07
1.12

The actual voltage should be 0.05 or 0.07, but for some reason it reads in a 1.12 or so.

Even more weirdly, when I close the serial monitor and re-open it, the input goes back to normal -- until it reaches 1.12 V again.

Any suggestions would be much, much appreciated. Oh, another problem is that the mic output seems to peak at 2.19V, not the expected 3.3 V.

Thanks!

P.S. The code I'm using is below:

const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz)
unsigned int sample;

Code: Select all

void setup() 
{
  Serial.begin(9600);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
}


void loop() 
{
  unsigned long startMillis= millis();  // Start of sample window
  unsigned int peakToPeak = 0;   // peak-to-peak level

  unsigned int signalMax = 0;
  unsigned int signalMin = 1024;
  // collect data for 50 mS
  while (millis() - startMillis < sampleWindow)
  {
    sample = analogRead(3);
    if (sample < 1024)  // toss out spurious readings
    {
      if (sample > signalMax)
      {
        signalMax = sample;  // save just the max levels
      }
      else if (sample < signalMin)
      {
        signalMin = sample;  // save just the min levels
      }
    }
  }
  peakToPeak = signalMax - signalMin;  // max - min = peak-peak amplitude
  double volts = (peakToPeak * 3.3) / 1024;  // convert to volts

  Serial.println(volts);

  if (volts > 0.5){
    digitalWrite(10, HIGH);
  }
  if (volts > 1){
    digitalWrite(10, HIGH);
    digitalWrite(9, HIGH);
  }
  if (volts > 1.5){
    digitalWrite(10, HIGH);
    digitalWrite(9, HIGH);
    digitalWrite(8, HIGH);
  }

  if (volts < 0.5) {
    digitalWrite(8, LOW);
    digitalWrite(9, LOW);
    digitalWrite(10, LOW);
  }
  if (volts < 1) {
    digitalWrite(9, LOW);
    digitalWrite(10, LOW);
  }

  if (volts < 1.5) {
    digitalWrite(10, LOW);
  }


}
Last edited by adafruit_support_bill on Thu Sep 04, 2014 6:58 am, edited 1 time in total.
Reason: please use the </> button when submitting code. press </>, then paste your code between the [code] [/code] tags.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Really weird problem w/ arduino input

Post by adafruit_support_bill »

Sounds like you might be picking up some electrical noise from somewhere that is affecting the sound level measurement. Post a photo showing your wiring.

User avatar
bxl5138
 
Posts: 6
Joined: Wed Sep 03, 2014 3:03 pm

Re: Really weird problem w/ arduino input

Post by bxl5138 »

Thanks for the response!

I ended up tearing it apart and rewiring it so everything was spaced apart; it works like it's supposed to now, more or less.

2 questions though:
1. How did you know it was a noise problem?
2. The output still maxes out at 2.2V instead of 3.3V -- any reason this might be happening? Should I just use an op-amp to amplify it more, or is there a way to increase the sensitivity?

Thanks again!

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Really weird problem w/ arduino input

Post by adafruit_support_bill »

How did you know it was a noise problem?
Just an educated guess. If the anomalous output occurred when you moved something, I would have suspected a cold solder joint.
The output still maxes out at 2.2V instead of 3.3V
Have you adjusted the gain pot on the back? Be very gentle when turning the pot. It is delicate and easy to damage if you turn it past the stop.

User avatar
bxl5138
 
Posts: 6
Joined: Wed Sep 03, 2014 3:03 pm

Re: Really weird problem w/ arduino input

Post by bxl5138 »

Yes, I've adjusted the pot on the back... I have it set to one of the extremes, and I'm pretty sure it's at the maximum gain (otherwise, would it even be able to reach 2.2V?).

Is the mic designed specifically for close range noise? I was hoping to use it to pick up music from speakers. Eventually, I was planning on using an FFT library to have it react to bass frequencies and pulse lights to the beat of music. Is that feasible, or would you recommend a different type of hardware?

Thanks again!

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Really weird problem w/ arduino input

Post by adafruit_support_bill »

I think the 2.2v problem is because you are scaling the readings for 3.3v, but you are using the default 5v analog reference. You need to set the reference to EXTERNAL and wire a jumper from 3.3v to AREF. http://arduino.cc/en/Reference/AnalogReference

If you search around, there are several FFT-based spectrum analyzer and/or color-organ projects based on this or similar mic amps.
https://learn.adafruit.com/fft-fun-with ... transforms
https://learn.adafruit.com/piccolo

User avatar
bxl5138
 
Posts: 6
Joined: Wed Sep 03, 2014 3:03 pm

Re: Really weird problem w/ arduino input

Post by bxl5138 »

Oh wow, I had never used AREF before -- that was super helpful. Thank you so much!

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”