const int trigPin = 8;
const int echoPin = 6;
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
float duration, distance;
void setup() {
lcd.init();
pinMode(11, OUTPUT);
lcd.backlight();
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration*.0343)/2;
if(distance<60){
digitalWrite(11,1);
}
else
digitalWrite(11,0);
Serial.print("Distance: ");
Serial.println(distance);
lcd.setCursor(0,0);
lcd.print("Distance: ");
lcd.setCursor(10,0);
lcd.print(distance);
delay(500);
}