Measuring delays with electrical signals

When you send the signal out, record the value of millis() or micros() in a variable called start. When the return signal is detected record the value of millis() or micros() in a variable called end. End minus start is the duration.