Progaram Code:: Distance
Progaram Code:: Distance
Progaram Code:: Distance
#include<Servo.h>
#include<LiquidCrystal.h>
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);
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");
return microseconds / 29 / 2 ;
}