#include <LiquidCrystal.h>
const int rs = 15, en = 2, d4 = 5, d5 = 18, d6 = 19, d7 = 21;
LiquidCrystal LCD(rs, en, d4, d5, d6, d7);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(12, OUTPUT);
pinMode(5, INPUT);
LCD.begin(16,2);
}
void loop() {
digitalWrite(12, LOW);
delayMicroseconds(2);
digitalWrite(12,HIGH);
delayMicroseconds(10);
digitalWrite(12, LOW);
delayMicroseconds(2);
float distance;
float duration = pulseIn(13,HIGH);
distance = (0.034*duration)/2;
LCD.setCursor(0,0);
LCD.print(distance);
delay(2000);
}