#include <LiquidCrystal.h>
int threshold = 45;
LiquidCrystal lcd(5,7,8,9,10,11);
void setup() {
pinMode(3, INPUT);
pinMode(A0, INPUT);
pinMode(4, OUTPUT);
pinMode(2,OUTPUT);
lcd.begin(16,2);
}
void loop() {
digitalWrite(4, HIGH);
delayMicroseconds(10);
digitalWrite(4, LOW);
delayMicroseconds(10);
lcd.setCursor(0,0);
float t = pulseIn(3, HIGH);
float d = (t*0.034)/8;
if (d<threshold){
digitalWrite(2,LOW);
}
else{
digitalWrite(2,HIGH);
}
lcd.print("Distance:");
lcd.print(d);
lcd.println("cm");
delay(500);
}
//#include <LiquidCrystal.h>
//LiquidCrystal lcd(13, 11, 10, 9, 8, 7);
//void setup()
//{
//lcd.begin(16, 2);
//lcd.print("hello, world!");
//}
//void loop()
//{
//lcd.setCursor(0,1);
// for (int i = 0; i <= 5; i++)
// {
// lcd.print("anil");
//delay(1000);
// }
//}