#include <Servo.h>
Servo myservo;
int pos = 0;
int micPin = A0;         
int gndPin = A1;
int powerPin = A2;
int micValue1 = 0;  
int micValue2 = 0; 
void setup() {
  myservo.attach(9);
  pinMode(powerPin, OUTPUT);
  pinMode(gndPin, OUTPUT);
  pinMode(micPin, INPUT);
  digitalWrite(gndPin,LOW);
  delay(500);
  digitalWrite(powerPin,HIGH);
  Serial.begin(9600);  
}
void loop() {
  micValue1 = analogRead(micPin);  
  Serial.println(micValue1);
  delay(1);
  micValue2 = analogRead(micPin);
  Serial.println(micValue2);
  if (micValue1-micValue2 > 2||micValue2-micValue1 > 2){
  for (pos = 0; pos <= 180; pos += 1) { 
    // in steps of 1 degree
    myservo.write(pos);              
    delay(15);                       
  }
  for (pos = 180; pos >= 0; pos -= 1) { 
    myservo.write(pos);              
    delay(15);                      
  }
  }
 }