Using two ultrasonic sensors for counting cars when they enter to a garage
If you have two sensors, you use analogRead.

int sensor1 = A0;
int sensor2 = A1;
int distance = 50; // or whatever you want here
bool car_passing = false;

void setup(){
    int counter = 0;
}

void loop(){
    if(analogRead(sensor1) &lt; distance &amp;&amp; 
       analogRead(sensor2) &lt; distance &amp;&amp; 
       !car_passing)
    {
        car_passing = true;
        counter++; 
    }

    if(analogRead(sensor1) &gt; distance){
        car_passing = false;
    }
}


To prevent the counter keep counting while the car is passing by, we need to make a boolean, so the counter does not wait for count again, before the car has passed.