 
     // obstacle is further away than X cm
     // and no obstacle in front of the IR sensor
-    if(!obstacleFound || wheelSpinCompleted && rangeCenter > rangeLimit_Stop)
+    if(!obstacleFound && wheelSpinCompleted && rangeCenter > rangeLimit_Stop)
     {
         rangeLimit_Timestamp = uptime;
 

            if(rangeRight > rangeLeft && rangeRight > rangeCenter )
            {
                // drive straight
                SetMotor(motorPin1_1, motorPin1_2, 255);
                SetMotor(motorPin2_1, motorPin2_2, 128);
            }

            if(rangeLeft > rangeRight && rangeLeft > rangeCenter )
            {
                // drive straight
                SetMotor(motorPin1_1, motorPin1_2, 128);
                SetMotor(motorPin2_1, motorPin2_2, 255);
            }
        }


        // drive straight
        SetMotor(motorPin1_1, motorPin1_2, 255);
        SetMotor(motorPin2_1, motorPin2_2, 255);

        return;
    }

const uint16_t initialDelay = 2500;

// Ranges and Data
const uint8_t rangeLimit_Warning1 = 60;
const uint8_t rangeLimit_Warning2 = 50;
const uint8_t rangeLimit_Warning3 = 40;
const uint8_t rangeLimit_Stop = 25;
const uint8_t motorSpeed = 255;

const uint16_t rangeLimit_RotateFor = 1000;
unsigned long rangeLimit_Timestamp = 0;
