Servo arm disrupting MIC/AMP sensor circuit


hello all!
i tried creating first bit of automation week ago. project turn on lightswitch servo arm when sound level met, hardware in place i'm newbie programming i'm getting error cant understand.
when use mic/amp circuit expected reading in serial port, picks music or claps, 0.05 1.1 clap. when try integrate servo arm in circuit goes top possible value, 2.37 , stays there reason.
my code using follows
const int samplewindow = 50; // sample window width in ms (50 ms = 20hz)
unsigned int sample;
//#include <servo.h>
//servo myservo;
//int pos = 0;
void setup()
{
// myservo.attach(9);
serial.begin(9600);
}
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 50 ms
while (millis() - startmillis < samplewindow) {
  sample = analogread(0);

  if (sample < 1024)  // toss out spurious readings

  {

     if (sample > signalmax)

     {


        signalmax = sample;  // save max levels

     }

     else if (sample < signalmin)

     {

        signalmin = sample;  // save min levels

     }

  }
}
peaktopeak = signalmax - signalmin; // max - min = peak-
peak amplitude
double volts = (peaktopeak * 3.3) / 1024; // convert volts
serial.println(volts);
if (volts > 0.65)
// for(pos = 0; pos <= 180; pos += 1) // goes 0 degrees to
180 degrees
{ // in steps of 1 degree
// myservo.write(pos); // tell servo go position in variable 'pos'
// while(true){}
}
}

i've commented out servo parts mic/amp sensor working, out of depth here, software problem or hardware problem due servo drawing current arduino?

any appreciated!
gary

are chance trying share 5v rail between arduino, mic amp , servo?
dont!!!

definitely need separate supply servo - common point should be
ground between servo power supply ground , arduino ground.

do have adequate power supply servo?

do have decoupling on supply?

what "mic/amp" circuit precisely, , how have wired up?


Arduino Forum > Using Arduino > Motors, Mechanics, and Power (Moderator: fabioc84) > Servo arm disrupting MIC/AMP sensor circuit


arduino

Comments