what could be more awsome than building your own robot,today im gonna explain how to build your own obstacle avoiding robot with a servo motor and an ultrasonic sensor.dont worry! I’ll guide you step by step through the processes.
so basically ,if you search online ,you will be able to find so many obstacle avoiding robots with different algorithms,in here the algorithm will be,
robot moves forwardwhen detect an obstacle with 35 cm range
stop
look right (40’) check for obstacle,if no obstacle is detected turn the ser vo to initial positon ,turn the chassis to right, move forward ,

if obstacle detected in rightside ,look left (130’),if no obstacle turn the servo to initial position turn the chassis left ,move forward in that direction

if obstacle detected in all 3 directions,rotate the robot chassis in 180 degrees and go forward.
now lets see how to build the robot.”

Link