#include <Servo.h>
// Define variables
int echopin = A0;
int trigpin = 7;
int Time;
int Distance;
Servo myservo;
void setup() {
pinMode(trigpin, OUTPUT);
pinMode(echopin, INPUT);
myservo.attach(11);
}
void loop() {
digitalWrite(trigpin, LOW);
delayMicroseconds(2);
digitalWrite(trigpin, HIGH);
delayMicroseconds(10);
Time = pulseIn(echopin, HIGH);
Distance = Time * 0.0172;
if (Distance > 30) {
myservo.write(90);
}
else {
myservo.write(0);
}
delay(100);
}