#include <Servo.h>
int trig = 3;
int echo = 6;
int distance;
int time;
Servo angle;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
angle.attach(5);
angle.write(0);
}
void loop() {
// put your main code here, to run repeatedly:
int a = distance;
digitalWrite(trig, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
time = pulseIn(echo, HIGH);
distance=time*0.034/2;
if(a<100)
{
angle.write(90);
delay(1000);
}
else
{
angle.write(0);
delay(1000);
}
}