Getting any circuit like this to work can be a HUGE effort, as you have analog, digital and code issues all running together, and usually, unless everything works, nothing works.

So take it in steps... and do please tell me you have an osciloscope. Without an oscilloscope there isn't much you can do with a non-working circuit but say a prayer.

So first, make sure the transmitter is getting a pulse train at 40 KHz. If not, make it so. Once you have that, look at what the reveiver is doing. Q2 collector should show you a burst of 40KHz pulses that are the echo; trigger the scope on the transmit burst and see how long the return burst takes.

Once you see that, you can adjust one of the pots (R17, R18 and R190 so it triggers on the "meat" of this burst. I don't know why there are 3 comparitors there, only one is needed to tell when the return happens.

I have done a similar circuit, I did not use comparitors, just a transistor between my receive amp to "square off" the return signal and use that to trigger an interupt, the ISR then read a timer to determin time of flight. Using interupts isn't essential but would be a bit more accurate then polling the port pins.