#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);

// Measures the pulse input of the echo pin
duration = pulseIn(echoPin, HIGH);

// Distance duration/2 devided by 29.1 (from datasheet)
distance = (duration/2) / 29.1;

// if distance less than 0.25 meter or more than 0
if (distance <= 25 && distance >= 0) {
	servo.write(25);
    delay(3000);
} else {
	
	servo.write(160);
}
// 60ms delay 
delay(60);
}