49Views0Replies

Author Options:

how do i start a project using a microphone to cause a servo to "sweep" depending on the sound level? Answered

i really want to make a servo rotate like when using the sweep code but with a microphone instead of a potentiometer. the servo would move depending on the decibel level and return to it's default position once the noise stops. i can code myself but i don't know where to start and i can't understand the microphone related code parts, i could really use some help with getting started, i would be greatful on many levels.
EDIT: i scraped this together but it doesn't work exactly how i want it to

#include <Servo.h>
int micPin = 1;    // select the input pin for the mic input
      // select the pin for the LED
int micValue = 1;  // variable to store the value coming from the mic
Servo servo09;

void setup()  
{               

    servo09.attach(9);   
}

void loop()                    
{
    micValue = analogRead(micPin);

// use what ever threshold between 0-1023 you wish to switch  the led

    if (micValue > 2)
    {


        servo09.write(10);
        delay(1);
    }
    else
    {


        servo09.write(100);
        delay(1);
    }
}

Comments

The forums are retiring in 2021 and are now closed for new topics and comments.