What will be line follower code for QTR 8A

The Example code is this how to modify it for QTR 8A sensor.

{
  uint16_t sensors[3];
  // Get calibrated sensor values returned in the sensors array, along with the
  // line position, which will range from 0 to 2000, with 1000 corresponding to
  // a position under the middle sensor.
  int16_t position = qtr.readLineBlack(sensors);
  // If all three sensors see very low reflectance, take some appropriate action
  // for this  situation.
  if ((sensors[0] > 750) && (sensors[1] > 750) && (sensors[2] > 750))
  {
    // Do something. Maybe this means we're at the edge of a course or about to
    // fall off a table, in which case we might want to stop moving, back up,
    // and turn around.
    return;
  }
  // Compute our "error" from the line position. We will make it so that the
  // error is zero when the middle sensor is over the line, because this is our
  // goal. Error will range from -1000 to +1000. If we have sensor 0 on the left
  // and sensor 2 on the right,  a reading of -1000 means that we see the line
  // on the left and a reading of +1000 means we see the line on the right.
  int16_t error = position - 1000;
  int16_t leftMotorSpeed = 100;
  int16_t rightMotorSpeed = 100;
  if (error < -500)
  {
    // the line is on the left
    leftMotorSpeed = 0;  // turn left
  }
  if (error > 500)
  {
    // the line is on the right
    rightMotorSpeed = 0;  // turn right
  }
  // set motor speeds using the two motor speed variables above
}

If you are asking about how to change the code to use all 8 sensors instead of 3, then you would first need to make sure you correctly specify the pins you are using in the setSensorPins() function, which should be called in setup(). You can see an example of this in line 38 of our QTRAExample.ino example sketch. Please note that the library only uses 6 pins in the example so it can be compatible with more Arduino boards (e.g. the Arduino Uno, which only has 6 pins capable of analog input). Next, you will need to change the sensors[] array to be big enough to hold all 8 readings instead of only 3 (i.e. uint16_t sensors[3]; should be uint16_t sensors[8];). Then, since the readLineBlack() function will now return a value between 0 and 7000, to make the 0 reading be the center of the sensor you can change int16_t error = position - 1000; to int16_t error = position - 3500;.

If you still have problems after that, could you post your complete updated program as well as more information about your setup, such as what other hardware you are using and some pictures of your setup that show all of your connections? Additionally, could you describe what is going wrong when you try to run your program?

By the way, your line following code uses a very simple approach and will probably result in jittery and sub-optimal performance. If you do not have a particular reason for sticking with that approach, you might consider adapting a more sophisticated control algorithm such as PID, which is very common in line following applications.

Brandon