This is a mini project to realise the application of the combination of ultrasonic sensor and servo module. The car barrier will automatically lift up when the ultrasonic sensor senses a vehicle coming.
A mini car barrier system that automatically lifts up when vehicle approaching.
To make the experience fit your profile, pick a username and tell us what interests you.
We found and based on your interests.
#include<AmebaServo.h>
AmebaServo myservo;
const int trigPin=3;
const int echoPin=5;
long duration;
int distance;
void setup() {
Serial.begin(9600);
myservo.attach(9);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// measure time duration of pulse HIGH at echo pin
duration=pulseIn(echoPin, HIGH);
// calculate the distance from car to sensor
distance=(0.034*duration)/2;
if(distance<=10){
myservo.write(90);
}
else{
myservo.write(0);
}
Serial.print("distance: ");
Serial.println(distance);
Serial.print(" cm");
delay(1);
}
Create an account to leave a comment. Already have an account? Log In.
Become a member to follow this project and never miss any updates
By using our website and services, you expressly agree to the placement of our performance, functionality, and advertising cookies. Learn More