         leftDir = 0;
       }
     }
-    if((leftDistance <= maximumRange && leftDistance >= minimumRange) &&
-       (rightDistance <= maximumRange && rightDistance >=minimumRange)) {
+    if((leftDistance <= maxRange && leftDistance >= minRange) &&
+       (rightDistance <= maxRange && rightDistance >=minRange)) {
         found = true;
         //Serial.println("FOUND");
       stop();  


/*
 * autonomous sumo test 1
 * simple h bridge controlling 2-wheel bot
 * HC-SR04 used for object detection
 * objective: search and push
*/

//motor A connected between A01 and A02
//motor B connected between B01 and B02

int STBY = 10; //standby

//Motor A
int PWMA = 3; //Speed control
int AIN1 = 8; //Direction
int AIN2 = 9; //Direction

//Motor B
int PWMB = 5; //Speed control 
int BIN1 = 12; //Direction
int BIN2 = 11; //Direction

//HC-SR04
#define leftEcho 2  // left Echo Pin
#define leftTrig 4  // left Trigger Pin
#define rightEcho 7 // right Echo Pin
#define rightTrig 6 // right Trigger Pin

// Distance variables and parameters
#define maximumRange 20 // Maximum range needed
#define minimumRange 1  // Minimum range needed
long leftDistance = 1000;
long rightDistance = 1000;
long prevLeft, prevRight;
long durationLeft, cmLeft, inchesLeft, cmRight, inchesRight, durationRight;

//search()
boolean found = false;  // used for search()
boolean lost = false;   // true after enemy is found for first time

//follow()
boolean tagged = false;
int rightDirMod = 0;
int leftDirMod = 0;

//speed variables and parameters
#define baseSpeed 128
int leftMod = 0;
int rightMod = 0;
int leftSpeed = 0;
int rightSpeed = 0;

int speedModifier;
int diff;
int diffMag;

int leftDir = 0;
int rightDir = 1;

//line sensor pins(temporarily RPR-220)
#define frontInput  A0
#define frontLed    13
#define leftInput   A1
#define leftLed     17
#define rightInput  A2
#define rightLed    18

//line sensor variables and parameters
#define lineThreshold 100
boolean initialize = true;
long frontBaseVal, leftBaseVal, rightBaseVal;
long frontVal, leftVal, rightVal;

void setup(){
  Serial.begin (9600);
  pinMode(STBY, OUTPUT);

  pinMode(PWMA, OUTPUT);
  pinMode(AIN1, OUTPUT);
  pinMode(AIN2, OUTPUT);

  pinMode(PWMB, OUTPUT);
  pinMode(BIN1, OUTPUT);
  pinMode(BIN2, OUTPUT);

  pinMode(leftTrig, OUTPUT);
  pinMode(leftEcho, INPUT);
  pinMode(rightTrig, OUTPUT);
  pinMode(rightEcho, INPUT);

  pinMode(frontInput, INPUT);
  pinMode(leftInput, INPUT);
  pinMode(rightInput, INPUT);
  pinMode(frontLed, OUTPUT);
  pinMode(leftLed, OUTPUT);
  pinMode(rightLed, OUTPUT);
  
  readLine();
}

void loop(){
  search();
}

//line sensors take calibration reading
void readLine() {
 int ambient = 0;
 int lit = 0;
 int value = 0;

 digitalWrite(frontLed, LOW);
 delay(5);                            //To give ADC and LED transition time
 ambient = analogRead(frontInput);
 digitalWrite(frontLed, HIGH);
 delay(5);
 lit = analogRead(frontInput);
 if(initialize) {
  frontBaseVal = lit - ambient;  
 }
 frontVal = lit - ambient;
 
 digitalWrite(leftLed, LOW);
 delay(5);                            //To give ADC and LED transition time
 ambient = analogRead(leftInput);
 digitalWrite(leftLed, HIGH);
 delay(5);
 lit = analogRead(leftInput);
 if(initialize) {
  leftBaseVal = lit - ambient;
 }
 leftVal = lit - ambient;
 
 digitalWrite(rightLed, LOW);
 delay(5);                            //To give ADC and LED transition time
 ambient = analogRead(rightInput);
 digitalWrite(rightLed, HIGH);
 delay(5);
 lit = analogRead(rightInput);
 if(initialize) {
  rightBaseVal = lit - ambient;
 }
 rightVal = lit - ambient;
 if(!initialize) {
  checkLine();
 } else {

  }
}

//follow
void follow() {
  while(!tagged) {
    calcDistance();
    diff = leftDistance - rightDistance;
    diffMag = abs(diff);

    if(!(leftDistance <= maxRange && leftDistance >= minRange) &&
       !(rightDistance <= maxRange && rightDistance >=minRange)) {
        found = false;
        lost = true;
        search();
