using ultrasonic range sensor to change text on lcd display

I am trying to use the ultrasonic range sensor to display certain texts at different distances. this is my code right now. I am having trouble implementing the changing text. I do have it displaying distance data.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <NewPing.h>
LiquidCrystal_I2C lcd(0x27,16,2);
#define TRIGGER_PIN 8 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 9 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 400 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

void setup()
{lcd.print(targetDistance); //Print measured distance

Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
lcd.init();
lcd.backlight();
}

void loop()
{if(targetDistance < 15){
lcd.print(targetDistance);
}
else {
lcd.print(“hello”);
}
{
delay(100); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
Serial.print("Ping: “);
Serial.print(uS / US_ROUNDTRIP_CM); // Convert ping time to distance in cm and print result (0 = outside set distance range)
Serial.println(“cm”);
lcd.setCursor(0, 0);
lcd.print(“hello:”);
lcd.setCursor(0, 1);
lcd.print(” ");
lcd.setCursor(9, 1);
lcd.print(uS / US_ROUNDTRIP_CM);
lcd.setCursor(12, 1);
lcd.print(“cm”);
}

can somebody please help me with this code? I am trying if then statements but im just not sure how to integrate them with the range sensor as a means of what to display rather than displaying the distance data .

What is "targetDistance"?

It looks very likely to me that that code doesn't compile, so it isn't ever going to work.

Please remember to use code tags when posting code

am I getting any closer?

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <NewPing.h>
LiquidCrystal_I2C lcd(0x27,16,2);

const int trigPin = 8; //connects to the echo pin on the distance sensor
const int echoPin = 9;
float distance = 0; //stores the distance measured by the distance sensor

void setup() {

{
Serial.begin (9600); //set up a serial connection with the computer

pinMode(trigPin, OUTPUT); //the trigger pin will output pulses of electricity
pinMode(echoPin, INPUT); //the echo pin will measure the duration of pulses coming back from the distance sensor

}

void loop() {

distance = getDistance(); //variable to store the distance measured by the sensor

Serial.print(distance); //print the distance that was measured
Serial.println(" in"); //print units after the distance
}

if(distance <= 10){ //if the object is close

lcd.setCursor(0,1); //Set cursor to column 0, row 1
lcd.print(“i have to talk to you i have to talk to you”); //Display the distance
lcd.print(“you arent real”);

} else if(10 < distance && distance < 20){ //if the object is a medium distance

lcd.setCursor(0,1); //Set cursor to column 0, row 1
lcd.print(“i cant to talk to you i cant to talk to you”); //Display the distance
lcd.print(“you are real”);

} else{ //if the object is far away

lcd.setCursor(0,2); //Set cursor to column 0, row 1
lcd.print(“goodbye goodbye goodbye”); //Display the distance
lcd.print(“talk to you never”);

}

delay(50); //delay 50ms between each reading
}
}

What is “getDistance”?

Please remember to use code…oh. I’ve already mentioned that.

how do I "use code" sorry I am knew here.

I am not sure. I am trying to use distance recorded by sensor to change the text that is displayed on lcd using if else statement.

are there any obvious problems that are getting in the way?am I missing any important setup functions?

Code tags are explained in the "how to use the forum" stickies. I'm not going to repeat what they say.

You are trying to call a function called "getDistance" but you haven't defined such a function.

Hi, Here’s an example; it’s more complicated than you need and also displays temperature. But it works…

/* YourDuinoStarter Example: Ultrasonic-Temp-LCD
 - WHAT IT DOES  Measures Distance with Ultrasonic Sensor, Displays result
 - SEE the comments after "//" on each line below
 - CONNECTIONS:
   -
   - Credits: "www.janhenrik.org"
 - V1.00 09/23/15
   Questions: terry@yourduino.com */

/*-----( Import needed libraries )-----*/

#include <Wire.h>     // I2C Library: Comes with Arduino IDE
// Get the LCD I2C Library here:
// https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
// Move any other LCD libraries to another folder or delete them
// See Library "Docs" folder for possible commands etc.
#include <LiquidCrystal_I2C.h>   //Display Library
#include <NewPing.h>             //Sensor Library

/*-----( DS18B20 Temperature Sensor Libraries )-----*/
#include <OneWire.h>
#include <DallasTemperature.h>

/*-----( Declare Constants and Pin Numbers )-----*/
#define ONE_WIRE_BUS 2 /*-(Connect to Pin 2 )-*/

#define TRIGGER_PIN  12  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     11  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). 
// Maximum sensor distance is rated at 400-500cm.

/*-----( Declare objects )-----*/
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

/* Set up a oneWire instance to communicate with any OneWire device*/
OneWire ourWire(ONE_WIRE_BUS);
/* Tell Dallas Temperature Library to use oneWire Library */
DallasTemperature sensors(&ourWire);

/*-----( Declare Variables )-----*/

int   distanceInches;
float TempF;

int   TempSkipLoop;  // Don't measure temperature every time..

void setup()   /****** SETUP: RUNS ONCE ******/
{
  /*-( Start up the DallasTemperature library )-*/
  sensors.begin();
  /*-----( Start LCD Library )-----*/
  lcd.begin(20, 4);

  /*-----( Show startup to LCD )-----*/
  lcd.setCursor(0, 0);
  lcd.print("Hello! YourDuino.com");
  delay(2000);   //delay of the message
  /*-----( Write Labels only once )-----*/
  lcd.clear();                     // Clear screen
  lcd.setCursor(1, 0);             // Set Cursor
  lcd.print("UltraSonic Sensor");        // text

  lcd.setCursor(2, 1);             // move Cursor
  lcd.print("Distance: ");         // Print "Distance"

  TempSkipLoop = 0;
}//--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  delay(500);     // Wait 50ms between pings, 29ms should be the shortest delay between pings.
  unsigned int uS = sonar.ping();  // Send ping, get ping time in microseconds (uS).


  lcd.setCursor(12, 1);            // move Cursor
  lcd.print("   ");
  lcd.setCursor(12, 1);            // move Cursor
  distanceInches = (uS / US_ROUNDTRIP_IN);
  if (distanceInches == 0)
    lcd.print("FAR");
  else
    lcd.print(distanceInches); // Convert ping time to distance in cm and print result (0 = outside set distance range)

  lcd.setCursor(15, 1);            // move Cursor
  lcd.print(" In");                 // print units

  /*---------( Get and display Temperature every 20 loops )----------*/
  if (TempSkipLoop == 0)
  {
    sensors.requestTemperatures(); // Send the command to get temperatures
    TempF = sensors.getTempFByIndex(0);
    lcd.setCursor(0, 3);
    delay(1);
    lcd.print("Temperature(F)=");
    lcd.print(TempF);
    TempSkipLoop = 20;
  }
  TempSkipLoop -- ;
  
/*----------( Show the distance )---------*/
  lcd.setCursor(12, 1);            // move Cursor
  lcd.print("   ");
  lcd.setCursor(12, 1);            // move Cursor
  distanceInches = (uS / US_ROUNDTRIP_IN);
  if (distanceInches == 0)
    lcd.print("FAR");
  else
    lcd.print(distanceInches); // Convert ping time to distance in cm and print result (0 = outside set distance range)

  lcd.setCursor(15, 1);            // move Cursor
  lcd.print(" In");                 // print units


}//--(end main loop )---

/*-----( Declare User-written Functions )-----*/


//*********( THE END )***********