Line follower

I am currently working on a line follower with the specifications from the following link.
http://learn.parallax.com/node/301
I am currently trying to write a code which will let this bot follow across a black path on a white colored table.
I am wondering if this code is going to work and if not how can I modify this code so that it will work?

#include <Servo.h>
Servo servoLeft;
Servo servoRight;
 
void setup()                                 // Built-in initialization block
{
  tone(4, 3000, 1000);                       // Play tone for 1 second
  delay(1000);                               // Delay to finish tone
  pinMode(10, INPUT);  
  pinMode(9, OUTPUT);   // Left IR LED & Receiver
 
  pinMode(2, OUTPUT);
  pinMode(3, INPUT);
  Serial.begin(9600);  
 
  servoLeft.attach(13);
  servoRight.attach(12);
}  
 
void loop()                                  // Main loop auto-repeats
{
  int irRight = irDetect(2, 3, 38000);
  int irLeft = irDetect(9,10, 38000);
  Serial.println(irLeft, irRight);
  delay(100);
 
  if (irLeft == 0 && irRight == 0) { // if IR LED/RECEIVER detects both sides
  servoLeft.writeMicroseconds(1300); // Left wheel clockwise
  servoRight.writeMicroseconds(1300); // Right wheel clockwise
 
  }
 
  else if (irLeft == 1 && irRight == 0){ //Right IR detected, Left IR not detected
  servoLeft.writeMicroseconds(1300); // Left wheel cclockwise
 
 }
  else if (irLeft == 0 && irRight == 1){ //Right IR not detected, Left IR detected
 servoRight.writeMicroseconds(1300); // Right wheel clockwise
 
 }
 else if (irLeft == 1 && irRight == 1) { // if both receivers detect nothing
   servoRight.writeMicroseconds(1700); //reverse left wheel
   servoLeft.writeMicroseconds(1700); //reverse right wheel
}
}
 
int irDetect (int irLedPin, int irReceiverPin, long frequency) {
  tone(irLedPin , frequency, 8);
  delay(1);
  int ir = digitalRead(irReceiverPin);
  delay(1);
  return ir;
}

It is much easier for everyone if you post your code here (in code tags please)

Generally you need to know what output the line sensor gives when over a light surface and a dark surface and write the program logic to suit. How many sensors are you using ? What type are they ? What do they output when over each type of surface ?

What have you tried so far ? If it didn't work then post the code and error messages, if any, and describe what failed.

UKHeliBob:
It is much easier for everyone if you post your code here (in code tags please)

Generally you need to know what output the line sensor gives when over a light surface and a dark surface and write the program logic to suit. How many sensors are you using ? What type are they ? What do they output when over each type of surface ?

What have you tried so far ? If it didn’t work then post the code and error messages, if any, and describe what failed.

I’m sorry, I felt as if I posted the whole code in a single post it would’ve felt like I was spamming the forum. I will edit it after this reply.

There are 2 IR receivers and also 2 IR LEDs. They are both pointed down towards the table at the black line. When the servo detects the color white (the table) I want it to pause and function in the appropriate manner.

I have only tried this so far as I was having trouble getting the two sensors to work. I am currently trying to look for more ways to write this code. The code compiles fine (so far) but I have not had the chance to test it (will test on thursday/friday). Until then, I want to optimise the code so that it is efficient and runs smoothly without any problems.

What values do you get when the line is not detected and when it is detected ?

UKHeliBob: What values do you get when the line is not detected and when it is detected ?

0 when detected, 1 when not detected. The problem is, they don't detect a specific color, only if an obstacle is there or not

When the servo detects the color white (the table) I want it to pause and function in the appropriate manner.

The servo is not a color sensor. It will never detect anything.

The problem is, they don't detect a specific color, only if an obstacle is there or not

Then you are not using the right kind of sensor.

baegmon: 0 when detected, 1 when not detected. The problem is, they don't detect a specific color, only if an obstacle is there or not

If they enable you to detect whether the line is there or not, it would be all you need.

If you want to know whether the sketch works, I suggest you try it.