Detection and measurement of approaching objects using optical sensors