Automatic parking barrier controls project

 Automatic parking barrier controls project using Arduino uno and ultrasonic sensor




Arduino program code..


#include<Servo.h>
Servo myservo;
const int trigPin=5;
const int echoPin=6;
long timeduration;
int distance;
void setup()
{ myservo.attach(9);
     pinMode(trigPin,OUTPUT); pinMode(echoPin,INPUT); Serial.begin(9600);
     }
void loop() { digitalWrite(trigPin,LOW); delayMicroseconds(2); digitalWrite(trigPin,HIGH); delayMicroseconds(10); digitalWrite(trigPin,LOW); timeduration=pulseIn(echoPin,HIGH);
     distance=(0.034*timeduration)/2;
     if(distance<=20)

{ myservo.write(90);
        
    delay(2000);
        }
    else{ myservo.write(0);} Serial.print("distance:"); Serial.println(distance);
    delay(10); }


Post a Comment (0)
Previous Post Next Post