
The HC-SR04 ultrasonic sensor is used to measure distance by sending ultrasonic waves and calculating the time taken for the echo to return. It has a transmitter that emits sound pulses and a receiver that listens for the echo. Based on the time interval, the sensor calculates the distance to an object. In this project, the sensor is mounted at the front of the robot to detect obstacles. If the measured distance falls below a threshold, Arduino instructs the motors to stop or turn. This sensor is low-cost, highly reliable, and easy to integrate into robotics systems.