#include <Servo.h>
int echopin = A0;
int trigpin = 7;
int Time;
int Distance;

Servo myservo;

void setup() {
  // put your setup code here, to run once:
  pinMode(trigpin, OUTPUT);
  pinMode(echopin, INPUT);
  myservo.attach(11);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(trigpin, LOW);
  digitalWrite(trigpin, HIGH);
  digitalWrite(trigpin, LOW);

  Time = pulseIn(echopin, HIGH);
  Distance = Time * 0.0172;

    if (Distance < 30) {
      myservo.write(90); // Angle of Rotation
      digitalWrite(12, LOW);
      digitalWrite(13, HIGH);
  }
  else {
      myservo.write(0); // Angle of Rotation
      digitalWrite(12, HIGH);
      digitalWrite(13, LOW);
  }

}