Follow these directions to build a car which will drive all over and avoid crashing.
Build the Robot Writer with directions here.
Take off the head, add the motion sensor, and then replace the head if you like.
First, write a simple program to move forward and then backward. See how it turns?
The write your own program to make it move, but back up (which makes it turn, too) when it senses it's going to crash.