0% found this document useful (0 votes)
29 views3 pages

Progaram Code:: Distance

This program code controls a servo motor and LCD display based on ultrasonic sensor distance readings to manage vehicle entry. It initializes the servo, LCD, and ultrasonic sensor. The main loop uses the sensor to check for objects 2-15cm away, triggers the servo to close entry and displays messages on entering vehicles. It counts the number of vehicles entered and displays the count on the LCD.

Uploaded by

Sathvik Gowda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views3 pages

Progaram Code:: Distance

This program code controls a servo motor and LCD display based on ultrasonic sensor distance readings to manage vehicle entry. It initializes the servo, LCD, and ultrasonic sensor. The main loop uses the sensor to check for objects 2-15cm away, triggers the servo to close entry and displays messages on entering vehicles. It counts the number of vehicles entered and displays the count on the LCD.

Uploaded by

Sathvik Gowda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

PROGARAM CODE:

#include<Servo.h>
#include<LiquidCrystal.h>

Servo myservo; // create servo object to control a servo


const int trigPin = 2;
const int buzzer=10;
const int echoPin = 4;
LiquidCrystal lcd( 12 , 11 ,5 ,4 ,3 , 2 );
int sensed;

void setup()
{
lcd.begin( 16 ,2 ); // Initialise the lcd with Row and Columns
myservo.attach(9); // attaches the servo on pin 9 to the servo object
sensed=0;
}

void loop()
{
long duration, cm;
pinMode(trigPin, OUTPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(20);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);

cm = microsecondsToCentimeters(duration); // Covert time into


distance

if ( cm > 2 && cm < 15)


{
lcd.setCursor(0,0);
lcd.print("PLEASE WAIT");
delay(1000);
myservo.write(140); // sets the servo position according to the scaled
value
lcd.print("PLEASE ENTER");
tone(buzzer,3000);
delay(1000);
noTone(buzzer);
delay(3000);
tone(buzzer,1000);
delay(1000);

sensed = sensed + 1; //Used to count the vehicles entered

lcd.setCursor(0,0);
lcd.print("PLEASE WAIT");
}
else
{
myservo.write(40); // sets the servo position according to the scaled
value
lcd.setCursor(0,0);
lcd.print("ENTRY OPEN");

lcd.setCursor(0,1);
lcd.print(" VEHICLES : ");
lcd.setCursor(12,1);
lcd.write("sensed");

long microsecondsToCentimeters(long microseconds)


{

// The speed of sound is 340 m/s or 29 microseconds per centimeter.


// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.

return microseconds / 29 / 2 ;
}

You might also like