Polou Sensor with a Millis

I am making a line following car that I wish to turn on a light half way through running. This code does that, but after the light turns on the car does not move again. How do I fix this Problem and get the car to start sensing again?

#include <AFMotor.h> //Adafruit Motor Shield Library. First you must download and install AFMotor library
#include <QTRSensors.h> //Pololu QTR Sensor Library. First you must download and install QTRSensors library

AF_DCMotor motor1(1, MOTOR12_1KHZ ); //create motor #1 using M1 output on Motor Drive Shield, set to 1kHz PWM frequency
AF_DCMotor motor2(2, MOTOR12_1KHZ ); //create motor #2 using M2 output on Motor Drive Shield, set to 1kHz PWM frequency

#define KP 2 //experiment to determine this, start by something small that just makes your bot follow the line at a slow speed
#define KD 5 //experiment to determine this, slowly increase the speeds and adjust this value. ( Note: Kp < Kd)
#define M1_minumum_speed 150 //minimum speed of the Motor1
#define M2_minumum_speed 150 //minimum speed of the Motor2
#define M1_maksimum_speed 250 //max. speed of the Motor1
#define M2_maksimum_speed 250 //max. speed of the Motor2
#define MIDDLE_SENSOR 4 //number of middle sensor used
#define NUM_SENSORS 5 //number of sensors used
#define TIMEOUT 2500 //waits for 2500 us for sensor outputs to go low
#define EMITTER_PIN 2 //emitterPin is the Arduino digital pin that controls whether the IR LEDs are on or off. Emitter is controlled by digital pin 2
#define DEBUG 0

//sensors 0 through 5 are connected to analog inputs 0 through 5, respectively
QTRSensorsRC qtrrc((unsigned char) { A4,A3,A2,A1,A0} ,NUM_SENSORS, TIMEOUT, EMITTER_PIN);

unsigned int sensorValues[NUM_SENSORS];
int LEDPIN = 7; //Identify the ‘lED’

unsigned long start_time;
unsigned long end_time;
#define WAITTIME 13

void setup()
pinMode(LEDPIN, OUTPUT); //Identify as output
start_time = millis();
end_time = start_time + WAITTIME*1000;

int lastError = 0;
int last_proportional = 0;
int integral = 0;

void loop()
unsigned int sensors[5];
int position = qtrrc.readLine(sensors); //get calibrated readings along with the line position, refer to the QTR Sensors Arduino Library for more details on line position.
int error = position - 2000;

int motorSpeed = KP * error + KD * (error - lastError);
lastError = error;

int leftMotorSpeed = M1_minumum_speed + motorSpeed;
int rightMotorSpeed = M2_minumum_speed - motorSpeed;

// set motor speeds using the two motor speed variables above
set_motors(leftMotorSpeed, rightMotorSpeed);
if(millis() <= end_time+3000 && millis() >= end_time){
//light led
digitalWrite (LEDPIN,HIGH); //Power to ‘LED’ (Light turn on)

void set_motors(int motor1speed, int motor2speed)
if (motor1speed > M1_maksimum_speed ) motor1speed = M1_maksimum_speed;
if (motor2speed > M2_maksimum_speed ) motor2speed = M2_maksimum_speed;
if (motor1speed < 0) motor1speed = 0;
if (motor2speed < 0) motor2speed = 0;

//calibrate for sometime by sliding the sensors across the line, or you may use auto-calibration instead
void manual_calibration() {

int i;
for (i = 0; i < 250; i++)

if (DEBUG) {
for (int i = 0; i < NUM_SENSORS; i++)
Serial.print(’ ');

for (int i = 0; i < NUM_SENSORS; i++)
Serial.print(’ ');

I assume the following code is what you are referring to when you refer to a light turning on halfway through. Do you wish the light to turn on 3 seconds after the robot starts following the line?

  if(millis() <= end_time+3000 && millis() >= end_time){
    //light led
    digitalWrite (LEDPIN,HIGH); //Power to 'LED' (Light turn on)

I am making a line following car

Please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum Your code is too long for me to study quickly without copying to a text editor.

This is not the correct way to use millis().

 if(millis() <= end_time+3000 && millis() >= end_time){

have a look at how it is done in Several Things at a Time. It is important always to use subtraction.