include

define buzzer 9 // Attach an LED to Digital Pin 9 (or use onboard LED)

int pos = 0;

Servo myservo; void setup() { myservo.attach(8); myservo.write(0); pinMode(buzzer, OUTPUT); // The buzzer is an Output Serial.begin(9600); }

void loop() {

int level = analogRead(A0); Serial.println(level);

while(analogRead(A0) >= 130 && analogRead(A0) <= 200){ tone(buzzer,1000,1000); delay(1000);

for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } delay(5000); for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } }

delay(7000);

}

Share this project:
×

Updates