I'm at a better situation, but stuck nonetheless

Hello, so i am trying to make a simple project. I am using an arduino uno and i want to use ultrasonic sensor to judge the distance and project it on 16*2 LCD. Based on the reading of the distance, there is displacement in the servo motor and change in colour in RGB light. At my first try, i couldn’t even make the LCD light up. I have changed my ultrasonic sensor, my breadboard and my connecting wires. Further i have checked all the hardware bits and they work fine perfectly on their own. Which makes me believe there is a problem with my code which is not letting me achieve the desired results. Could someone help? The images attached are the only 2 readings i get.

I have deliberately put all the commands to servo in comments. I wanted to focus on the sensor and LCD and make it work.

#include <Servo.h>      //include servo library
#include <LiquidCrystal.h>    //include LCD library
/*
int pos = 0;        //Variable to store the servo position
int servoPin = 9;   //Servo is hooked to pin 9
int servoDelay = 25;    //25 milliseconds delay after each servo write
Servo mainMotor;      //Assigning a name to the servo motor.
float servoAngle;     //Angle we would want the servo to move
*/

LiquidCrystal LCD(10, 9, 5, 4, 3, 2);    //Define RS, E, DB4, DB5, DB6 and DB7

int trigPin = 13;      //Pin that is responsible for sending out the wave (Digital)
int echoPin = 6;      //Pin that is responsible for recieveing the wave (Analog)
float pingTime;       // Distance taken by the sound wave to hit the target and come back
float targetDistance;   //Distance of the target from the sensor
int soundSpeed = 33400;   //Speed of sound in cm/micros

int redPin = 13;    //Assigning the red pin to pin 13 of arduino
int greenPin = 12;   //Assigning the green pin to the pin 12 of arduino 
int bluePin = 7;    //Assigning the blue pin to the pin 7 of arduino
int rBrightness;    //analog value for the brightness of red LED  
int gBrightness;    //analog value for the brightness of green LED
int bBrightness;    //analog value for the brightness of blue LED

void setup() {
  
    // mainMotor.attach(servoPin);     //Telling the arduino to fix the servo mainMotor with the pin assigned as sevoPin.
//    pinMode(servoPin, OUTPUT);      //Declaring that the servoPin is an output
     Serial.begin(9600);
    LCD.begin(16,2);    //Defining the size of the LCD. In this case, 16 columns and 2 rows.
    LCD.setCursor(0,0); //Placing the cursor on the first column of the first row.
    
    pinMode(trigPin, OUTPUT);    // Telling arduino trigPin is an output
    pinMode(echoPin, INPUT);     //Telling arduino that echoPin is an input
    
    pinMode(redPin, OUTPUT);      //Telling arduino redPin is an output
    pinMode(bluePin, OUTPUT);     //Telling arduino bluePin is an output
    pinMode(greenPin, OUTPUT);    //Telling arduino greenPin is an output
    
    
    LCD.print("Object is- ");
    
    
}

void loop() {
  
  digitalWrite(trigPin, LOW);   //a pulse is set to low
  delayMicroseconds(2000);      //wait
  
  digitalWrite(trigPin, HIGH);  //the pulse is generated from the trigPin
  delayMicroseconds(1500);        //wait
  
  digitalWrite(trigPin, LOW);   //the pulse wave is switched off again
  delayMicroseconds(10);        //wait
  
  pingTime = pulseIn(echoPin, HIGH);      //time taken is equal to the time taken by echoPin to recieve the pulse signal sent by trigPin.
  pingTime = pingTime/1000000;            //conversion from microseconds to milliseconds  
  targetDistance = soundSpeed*pingTime;   //calculating distance
  targetDistance = targetDistance/2;    //Calculating distance in cm.
  Serial.println(pingTime);
  
  if (targetDistance > 35) {            //if the distance is more than 35cm
    LCD.setCursor(12,0);                  //setting the cursor location
    LCD.print("far");
    LCD.setCursor(0,1);
    LCD.print(targetDistance);
    LCD.print(" ");
    LCD.print("cm");
    delay(1000);                          //wait
    
    gBrightness = 8*targetDistance-230;   //by plotting graph where Y axis is LED brightness and X axis is targetDistance.
    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, gBrightness);
    analogWrite(bluePin, LOW);
    
 //   servoAngle = 0;
    
  }
  
   if (targetDistance < 35 && targetDistance > 15 ) {
    LCD.setCursor(12,0);
    LCD.print("arnd");
    LCD.setCursor(0,1);
    LCD.print(targetDistance);
    LCD.print(" ");
    LCD.print("cm");
    delay(1000);
    
    bBrightness = 10*targetDistance-100;
    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, LOW);
    analogWrite(bluePin, bBrightness);
    
  //  servoAngle = 0;
  }
  
   if (targetDistance < 15) {
    LCD.setCursor(12,0);
    LCD.print("    ");
    LCD.setCursor(12,0);
    LCD.print("near");
    LCD.setCursor(0,1);
    LCD.print(targetDistance);
    LCD.print(" ");
    LCD.print("cm");
    delay(1000);
    
    rBrightness = (13.3*targetDistance) + 50;
    digitalWrite(redPin, rBrightness);
    digitalWrite(greenPin, LOW);
    analogWrite(bluePin, LOW);
    
//    servoAngle = 12*targetDistance - 10;    //Relation between movement of servo and target distance.

  }
  
  
  
  
  
    
}

You have the LCD and the servo using the same pin. Same for trigPin and redPin. I stopped looking at that point.

okay, i changed the redPin, but the code still doesn't work. As for the servo, its in the comments. I am not using it in the code.

Let's see your wiring and schematic.

Let's see the sketch with the above changes.

What does this mean?
"there is displacement in the servo motor and change in colour in RGB light."

What does this mean?
"my code which is not letting me achieve the desired results. "

Try

void loop()
{
  digitalWrite(trigPin, LOW);   //a pulse is set to low
  delayMicroseconds(2);         //wait

  digitalWrite(trigPin, HIGH);  //the pulse is generated from the trigPin
  delayMicroseconds(10);        //wait

  digitalWrite(trigPin, LOW);   //the pulse wave is switched off again

  pingTime = pulseIn(echoPin, HIGH);   //time taken is equal to the time taken by echoPin to recieve the pulse signal sent by trigPin.
  Serial.println(pingTime);
  
  targetDistance = pingTime*0.034/2;   //calculating distance
  Serial.println(targetDistance);
int soundSpeed = 33400;   //Speed of sound in cm/micros

This has two problems.

A: The speed of sound is 343 Meters per Second, so...
34300 Centimeters per Second
34.3 Centimeters per Millisecond
.0343 Centimeters per Microsecond
It's off by a factor of 1 Million.

B: The number 33400 is larger than will fit in an 'int' (32767 maximum). It will appear to be negative.

Thank you so much. I shall try all of the suggestions posted here. Hopefully one of them would work. I would let you know which ever one of them worked, if all of them worked, or none of them worked. I hope it would help someone else in similar problem to go through with the post.

The contrast pot is not wired properly.

The code changes offered in post #4 should work.

Fritzing diagrams are almost always misleading, if not wrong.

okay, i tried and changed my program as per the post number 4

void loop()
{
  digitalWrite(trigPin, LOW);   //a pulse is set to low
  delayMicroseconds(2);         //wait

  digitalWrite(trigPin, HIGH);  //the pulse is generated from the trigPin
  delayMicroseconds(10);        //wait

  digitalWrite(trigPin, LOW);   //the pulse wave is switched off again

  pingTime = pulseIn(echoPin, HIGH);   //time taken is equal to the time taken by echoPin to recieve the pulse signal sent by trigPin.
  Serial.println(pingTime);
  
  targetDistance = pingTime*0.034/2;   //calculating distance
  Serial.println(targetDistance);

Now, the program worked for about 10 seconds. And then, out of nowhere, it stopped working. Now my guess is that my ultrasonic hardware somehow or something. I shall order new hardware for me. Regardless, i achieved the results i was looking for. Thanks a lot to all of you.