Trouble w/ Line Following Robot Code "Making Robot Stop on Finish Line"

Introduction:

A group of us ordered a Line Following Robot from SparkFun and made some adjustments to existing code because all we need the robot to do is 1.) Follow the Line 2.) Stop on the Finish Line. The robot follows the Line fairly well but I'm sure we could improve the code. However, we cannot get the robot to stop on the finish line. The track consists of an oval "black line" and the finish line "black line" as well that is perpendicular to the oval track like any finish line is in general.

We've commented on our code and at the very end "Case 5" we are trying to throw in another control function that will make the robot stop. Currently the robot has three IR modules on the bottom. Only two are being used to follow the line. The other we're trying to use in "Case 5" to sense the finish line and stop. Maybe there is a better way to do this but we could really use some help cause we're lost on why it is not stopping.

Code:

// Included these libraries as they were here with the initial code I worked with. To afraid
// to delete them so leaving them there. 
#include <RedBot.h>
#include <Servo.h>
#include "notes.h"

// Instantiate the motors.
RedBotMotor motors;

//I'm only going to use lSen (left sensor) and rSen (right sensor) to do the line following.
//I'm going to use the farl (far left) sensor to detect the finish line to make robot stop
RedBotSensor lSen = RedBotSensor(A6);
RedBotSensor rSen = RedBotSensor(A7);
RedBotSensor farl = RedBotSensor(A3);

// Create an alias for the onboard pushbutton.
#define BUTTON_PIN 12

// Constants for the levels that determine detection of the line.
const int bgLevel = 600;
const int lineLevel = 700;

void setup()
{
  Serial.begin(57600);
  // Set up our two built-in IO devices- the button and the LED.
  pinMode(BUTTON_PIN, INPUT_PULLUP);

}

void loop()
{

  if (digitalRead(BUTTON_PIN) == 1)
 {
    // Line following code: turn away from any sensor that is above the line
    //  threshold.
    // Case 1: both white. Drive forward!
    if (lSen.read() < bgLevel && rSen.read() < bgLevel && farl.read() < bgLevel) motors.drive(100);
    // Case 2: right sensor is on black. Must recenter.
    if (rSen.read() > lineLevel) 
    {
      motors.rightDrive(-200);
      motors.leftBrake();
    }
    // Case 3: left sensor is on black. Must recenter.
    if (lSen.read() > lineLevel) 
    {
      motors.leftDrive(-200);
      motors.rightBrake();
    }
    // Case 4: both sensors see dark
    if (lSen.read() > lineLevel && rSen.read() >lineLevel)
    {
      motors.leftDrive(-200);
      motors.rightDrive(-200);
    }
    // Case 5: see the finish line and stop
    if (farl.read() > lineLevel && rSen.read() > lineLevel && lSen.read() > lineLevel)
    {
      motors.brake();
    }
  }
  else motors.brake();
}

I would suggest that this line is going wrong.

   if (farl.read() > lineLevel && rSen.read() > lineLevel && lSen.read() > lineLevel)

So to find out why, i'd be inclined to connect a pushbutton to between GND and a spare i/o pin.
then within your setup function add

pinMode(yourChosenPinHere,INPUT_PULLUP);

then within your loop put in the following statement.

if(digital.read(button)==LOW)
  {
  Serial.println(farl.read() );  
  Serial.println(rSen.read());
  Serial.println(lSen.read());
  Serial.println((farl.read() > lineLevel && rSen.read() > lineLevel && lSen.read() > lineLevel));
  }

Plug it into a laptop. hold it just above the finish line and push the button. See what it's getting and then work through the logic to see why it isn't working.

    if (lSen.read() < bgLevel && rSen.read() < bgLevel && farl.read() < bgLevel) motors.drive(100);

There are several problems here. First, the first thing you should do in loop() is determine if you need to do anything. If you've arrived at the finish line, there is nothing to do.

Second, you should read the three sensors ONCE per iteration of loop(). Store the values, and use the stored values.

Third, it's ONE statement per line.