You can use an ultrasonic to measure the amount of distance. Ultrasonic Ranging Sensor is a non-contact distance measurement module with stable performance and high ranging accuracy, with the inexpensive price. The measurement range can be up to 5M, which would be helpful for your project such as robotic obstacle avoidance and so on.