Using ultrasonic sensor to detect wall when robot is driving

  1. That's not all you're all your code so we're unable to tell you whre the lag is comming from. But my guess, you use some more delay()'s...

  2. From the datasheet:

we
suggest to use over 60ms
measurement cycle, in order to prevent trigger sign
al to the echo signal.

Do you actually do that?

Small tip, numbering things is stupid. In case of variables, use an array. In case of functions, give it a damn parameter.

Extra tip, keep functions small. The name of the function should tell everything the function does. each1() does wayyyyy more then sending out an echo :wink: