You are on page 1of 1

#include<Servo.

h>

Servo myservo;
const int eko=8;
const int trig=7;
int mesafe;
int sure;

void setup() {
// put your setup code here, to run once:
myservo.attach(9); o
pinMode(trig,OUTPUT);
pinMode(eko,INPUT);

void loop() {
// put your main code here, to run repeatedly:
myservo.write(0);
Serial.begin(9600);

digitalWrite(trig,LOW);
delayMicroseconds(10);
digitalWrite(trig,HIGH);
delayMicroseconds(20);
digitalWrite(trig,LOW);
sure = pulseIn(eko,HIGH);
mesafe= (sure/29.1)/2;

if(mesafe<=5){
myservo.write(160);
delay(5000);
}
if(mesafe>200)
mesafe=200;
Serial.print("mesafe");
Serial.println(mesafe);
delay(500);
}

You might also like