Use an HC-SR04 ultrasonic sensor to give your robot the perception of distance. This popular ultrasonic distance sensor provides stable and accurate distance measurements from 2cm to 450cm Once there is an output, you can start the timer. This is the time of this distance measurement, and then you can calculate the distance. Working voltage: DC 5V; Working current: 2., 2mA; Working temperature: 0~+70°; Output mode: GPIO; Sensing angle: less than 15 degrees; Detection distance: 2cm-400cm; Detection accuracy: 0., 3cm+1%; Size: 1., 73*0., 79*0., 58 (44mm*20mm*14., 8mm); Weight: 0., 25 ounces (7g) , Working principle: 1., Use IO to trigger the distance measurement, and give a high-level signal of at least 10us; 2., The module automatically sends 8 10khz square waves and automatically detects whether there is a signal return; 3., If there is a signal return, a high level is output through IO. HC-SR04 Ultrasonic Sensor Module For Distance Measuring With Arduino Or Other Microcontrollers I391080842 Ultrasonic Module With Bracket Ultrasonic Sensor - HC-SR04 - HC-SR04 By continuously testing in this way, you can reach the value of your mobile measurement Package included:8pcs HC-SR04 Ultrasonic Sensor Module, 4pcs Mounting Bracket Distance Sensor, 2pcs 20CM 10P Male to Female Dupont Wire, 8pcs Screws HC-SR04 Ultrasonic Sensor Module - Flux Electronix Compatible with Arduino R3 MEGA2560 Duemilanove Nano Robot XBee ZigBee etc