This robot avoids obstacles in its way by using the ultrasonic ranging sensor HC-SR04. This sensor allows the robot to sense any object in front of it. In combination with this, I used the L298N H-Bridge to control the wheels of the robot. When an object is detected in close proximity, the robot will stop, go in reverse, and look for a clear path with the help of the ranging sensor.”

Link