this is what i tried. I'm just a beginner but this is my topic for school and i like to work with arduino so I will try till it works. I appreciate that you are helping me to find my solution
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows
int trigPin = 9; // TRIG pin
int echoPin = 8; // ECHO pin
float duration_us, distance_cm;
void setup()
{
Serial.begin(9600); //Serial baud rate
lcd.begin (16,2);
lcd.init(); // initialize the lcd
lcd.backlight();
lcd.home ();
lcd.print(distance_cm);
delay(2000);
lcd.clear();
// configure the trigger pin to output mode
pinMode(trigPin, OUTPUT);
// configure the echo pin to input mode
pinMode(echoPin, INPUT);
}
void loop()
{ // generate 10-microsecond pulse to TRIG pin
digitalWrite(trigPin, HIGH);
delayMicroseconds(10000);
digitalWrite(trigPin, LOW);
// measure duration of pulse from ECHO pin
duration_us = pulseIn(echoPin, HIGH);
// calculate the distance
distance_cm = 0.017 * duration_us;
// print the value to Serial Monitor
lcd.print(distance_cm);
delay(500);
}