distance = (duration/2) / 29.1;
// if distance outside 5 - 20 cm range
if(distance>15){
obstacle = false;
advance (200,200);
}
else {
if(distance<=10){
back_off (200,200);
}
else{
A: If the sensor isn't working or no echo is detected pulseIn() returns 0 which would cause the repeated back_off(). You might get better results if you treat 0 the same as >15.
B: Your comment about 5-20 cm range doesn't match the code