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 (with an additional turn for forward/backward actions) that was last taken that caused one of the sensors to be activated.

Getting ready

You 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 image are two possible sensors that will cause the switch to activate ...

Get Raspberry Pi for Python Programmers Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.