#include<Servo.h>
servo servo;
int const trigPin =6;
int const echoPin = 5;


void setup() {
  
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin, INPUT);
    servo.attach(3);
    
}

void loop() {
  (
    int duration, distance;
    digitalWrite(trigPin, HIGH);
    delay(1);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    distance = (duration/2) / 29.1;
    if (distance <= 50 && distance >= 0){
      servo.write(50);
      delay(3000);
    }
    else
    {
        servo.write(160);
    }
    delay(60);
  )
}