Back to Parent

#include <Servo.h>

Servo myservo;  // create servo object to control a servo

int micPin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin
int pos = 0;

void setup()
{
  Serial.begin(9600);
  myservo.attach(9);
  
}

void loop() 
 {
  
  val = analogRead(micPin);            
  val = map(val, 0, 1023, 0, 450);    
  //myservo.write(val);                   
  delay(10);

Serial.println(val); 
  
  if ((val > 20) && (val <= 30))  {
    for(pos = 0; pos <= 60; pos +=5)
    {
      myservo.write(pos);
      delay(20);
    }
  }
   
  
 
  if (( val >= 30 ) && (val < 100)) {
  //digitalWrite(micPin, HIGH); 
   for(pos = 0; pos <=60 ; pos +=5)
   {
    myservo.write(pos);
    delay(10);
   }
  } 

  if ( val > 100) {
   for(pos = 0; pos <=60 ; pos +=5)
   {
    myservo.write(pos);
    delay(3);
    }
  }
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0