Problem about Ultrasonic Sensor

I made a Speed Measuring instrument by using two Ultrasonic Sensors.
TRIG_PIN and ECHO_PIN are the group of first Ultrasonic Sensor.
and TRIG_PIN1 and ECHO_PIN1 are the group of second Ultrasonic Sensor.
When ECHO_PIN1 is High, Icd stop to
calculate time and show speed and spending time.
But It isn’t working. I don’t know how to fix this. so can you help me?

BACKUP228.ino (1.6 KB)

Welcome to the Forum. Please read this post: How to use this forum - please read. Please post your code using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpreted by the forum code as italics or funny emoticons. The "Code: [Select]" feature allows someone to select the entire sketch so it can be easily copied and pasted into the IDE for testing.

Unless the sketch is too large, it's better if you post your code, rather than attach it. When it's attached, we have to download it, create a folder then open your code in our IDE. And afterwards, the folder remains unless we navigate to the "Temp" folder and manually remove it. It's much easier to just view the code in your post.

   while( distance > 20)
   {
   
     c = millis();
   i1 = (c - a) / 1000;
   i2 = 180000 / (c - a);
   lcd.print(i1);
   lcd.setCursor(11,0);
   lcd.print("Sec's");
   lcd.setCursor(0,0);

   Serial.println("\n");
   Serial.println(i1);
   Serial.println("Sec's");
   Serial.println("........");
   Serial.println(i2);
   Serial.println("km/h");
   Serial.println("\n--------");
   delay(1);
   }

If distance IS greater than 20, the universe will end before this while loop does.

This is how your sketch should have been posted:

#include <LiquidCrystal.h>
#define TRIG_PIN 9
#define ECHO_PIN 10
#define TRIG_PIN1 11
#define ECHO_PIN1 12
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

void setup()
{
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  pinMode(TRIG_PIN1, OUTPUT);
  pinMode(ECHO_PIN1, INPUT);
  lcd.begin(16, 2);
  lcd.clear();

  Serial.begin(9600);

  pinMode(13, INPUT);
  digitalWrite(13, HIGH);
}

double i1 = 0;
double i2 = 0;
double a = millis();
double c ;

void loop()
{
  int distance = 0;
  int distance1 = 0;

  digitalWrite(TRIG_PIN1, HIGH);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN1, LOW);
  distance1 = pulseIn(ECHO_PIN1, HIGH) / 58.2;

  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, LOW);
  distance = pulseIn(ECHO_PIN, HIGH) / 58.2;

  lcd.clear();
  lcd.print("Just run.");
  delay(10);

  if (distance1 <= 20 & distance > 20 ) {
    lcd.clear();
    a = millis();
    while ( distance > 20)
    {

      c = millis();
      i1 = (c - a) / 1000;
      i2 = 180000 / (c - a);
      lcd.print(i1);
      lcd.setCursor(11, 0);
      lcd.print("Sec's");
      lcd.setCursor(0, 0);

      Serial.println("\n");
      Serial.println(i1);
      Serial.println("Sec's");
      Serial.println("........");
      Serial.println(i2);
      Serial.println("km/h");
      Serial.println("\n--------");
      delay(1);
    }

    if (distance <= 20 & distance1 > 20)
    {

      lcd.setCursor(0, 0);
      lcd.print(i1);
      lcd.setCursor(11, 0);
      lcd.print("Sec's");
      lcd.setCursor(0, 1);
      lcd.print(i2);
      lcd.setCursor(12, 1);
      lcd.print("km/h");
      lcd.setCursor(0, 0);
      delay(2000);
    }
  }
}