ZERO VALUE help! HC-SR04

So I have two Ultrasonic that I use in two different program that would run at the same time (in my project but I test it by running them individually), however I realized that everytime I try to run each of the program, and check the serial monitor it ended up showing only the value of “0” and I try fixing the pins; ( and when I slightly jerk the pin upward a large value suddenly pops in the serial monitor then returns to only showing “0”

here are the program that I run individually;

#define trigpin 4
#define echopin 5
#define R 7
#define G 8
#define B 9
//5V
void setup()

{ //serial monitor and pin setup.
  Serial.begin(9600);
  pinMode(trigpin, OUTPUT); //set trigpin as output
  pinMode(echopin, INPUT); //set echopin as input
  pinMode(R, OUTPUT); // set R,G and B as outputs
  pinMode(G, OUTPUT);
  pinMode(B, OUTPUT);


  // put your setup code here, to run once:

} void loop()

{

  //the trigpin sends out a signal, which bounces off an obstacle and comes back, the
  //echopin recieves this signal and gives out +5v setting the arduino pin on which it is connected to high.
  //distance= time*speed, but this distnce is divided by 2 because signal sent out returns
  //so distance= (the time it takes for the signal to leave and return)/2.
  //i.e if the time is 6s the distance = (6s/2) = 3m or cm.

  int durationl, distancel;//declare distance and duration as integers
  
  digitalWrite(trigpin, HIGH); // trigin send out signal
  delayMicroseconds(1000);//coninously for 1000ms
  digitalWrite(trigpin, LOW);// then goes low

  durationl = pulseIn(echopin, HIGH); // duration is the pulseIn to the echopin
  distancel = durationl*0.034/2; //  the 29.1 is used to convert the distnce to cm, the value varies for other units.

  if (distancel > 0 && distancel <= 20) { //distcance is greater than 0 and less than 20cm
    digitalWrite(G, LOW); //green led is off
    digitalWrite(B, LOW); //blue led is off
    _delay_ms(500);//delay
    digitalWrite(R, HIGH); //red led is on
    _delay_ms(500);
  }
  else if (distancel > 20 && distancel <= 80) { //distcance is greater than 20 and less than 80cm
    digitalWrite(R, LOW); //red led is off
    digitalWrite(G, LOW); //green led is off
    _delay_ms(500);
    digitalWrite(B, HIGH); //blue led is on

  }

  else if (distancel > 80 && distancel <= 180 ) { //distcance is greater than 80 and less than 120cm
    digitalWrite(R, LOW); //red led is off
    digitalWrite(B, LOW); //blue led is off
    _delay_ms(500);
    digitalWrite(G, HIGH); //green led is on
  }
  Serial.print("cm");
  Serial.println(distancel);//print values on serial monitor
  _delay_ms(100);
}


// put your main code here, to run repeatedly:

and here

#include <Servo.h>
Servo servo1;
int trigPin = 2;
int echoPin = 3;
long distance;
long duration;
 
void setup() 
{
servo1.attach(6); 
 pinMode(trigPin, OUTPUT);
 pinMode(echoPin, INPUT);// put your setup code here, to run once:
 Serial.begin(9600);
}
 
void loop() {
  Serial.println(distance);
  delay(50);
  ultra();
  if(distance <= 10){
  servo1.write(-90);
  delay(10);
  servo1.write(0);
  }
}
 
void ultra(){
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration*0.034/2;
  }

I got some of the programs online; because I’m only a begginer, Thank you in advance!

I'm missing the wiring diagram of your setup and links to the used hardware!

pylon:
I'm missing the wiring diagram of your setup and links to the used hardware!

i'm using Arduino Uno
for the first one the trigpin is on 4 then echopin to 5; then GND to GND and VCC to 5V

for the second one for the first one the trigpin is on 2 then echopin to 3; then GND to GND and VCC to 5V

the 5V and GND of the uno is connected to a breadboard and then I connect the GND and 5V of the ultrasonic sensor there.

Still missing a wiring diagram. Pencil and paper works amazingly well.

boolgalIDE:
So I have two Ultrasonic that I use in two different program that wwhen I slightly jerk the pin upward a large value suddenly pops in the serial monitor then returns to only showing "0"

Then you say:

boolgalIDE:
the uno is connected to a breadboard

The first is a sign of, the second a source of poor electrical connections.