MHz Speed Analog Reading + High Quality 40kHz Square Wave

liudr:
How do you account for amplitude changing with distance?

You tune the amplifier so that at max range (minimum amplitude), your output is just above the digital-high threshold for your microcontroller. This set point wil be a trade off between range/sensitivity and noise immunity. Output swing will be limited by your choice of op-amp supply voltage.