Get rid of the fixed time for the turn. Have it keep turning until the obstacle is cleared. The IF IT IS LESS AND 30 UNITS TURN part of the code will keep it turning until it is no longer less than 30 units from an obstacle. You will need to have the event that changes the variable from left to right choice, triggered by it clearing the obstacle and going straight again. As long as the obstacle is close, the main loop of the code will keep it turning. That's the way I have mine programmed and it works slick. Turns just enough to clear then goes straight.