Avoiding objects and obstacles
To avoid obstacles, you can place sensors around the robot's perimeter to activate whenever an object is encountered. Depending on how you want your robot to behave, one avoidance strategy is to just reverse any action last taken (with an additional turn for forward/backward actions) that caused one of the sensors to be activated.
Getting ready
You will need some micro switches to be triggered when there is an impact with objects. Depending on the type you have, you need to place enough switches to detect any object around the outside (if required, you can use an additional length of wire to extend the reach of the switch). Shown in the following photo are two possible sensors that will cause the switch to activate when the spring or the metal arm hits an object. You need to determine which contacts of the switch open or close the circuit (this will depend on the device):
Small micro switches can be used as collision sensors
How to do it...
Connect the switches...