QTR3-RC Line Following Question

Hi, I am working on a robot for my daughter (she’s 4). I purchased a QTR3-RC. The robot is controlled by her programming it with wooden instruction blocks and a barcode reader (to “program” the robot). If the robot is moving and it detects a line, I want it to automatically start following the line until there is no line. I have hooked up the sensor and have run the test programs to see the values that the sensor produces but I have found it hard to get consistent results. My thought would be to do the calibration and right afterward to assign those values to variables and if the robot is moving to compare those values to what the sensor is currently reading. I’m having a problem determining how the sensor values would be different if there is a line or no line. And would it be better to compare the calculated “error” or the raw sensor values? Thanks for any help.


I am sorry you are having trouble using the QTR-3RC to get your robot to follow a line. You might try reading through the “Pololu QTR Sensor Functions” section of the Pololu AVR C/C++ Library User’s Guide and the “QTR Reflectance Sensors” section of Pololu AVR Library Command Reference to get an idea of how to calibrate the sensors and use their output to follow a line.

I am not sure what microcontroller you are using or how you are programming your robot, but if you post the simplest version of your code that you think should work but doesn’t, I might be able to suggest something. If you post your code, can you also describe specifically what you expect your code to do, and what your robot is doing instead?


Thanks for the info. I did review the guides you suggested but still had a problem. I am using an arduino.

This is my code:

//****************calibrate qtr Serial.print("calibrating qtr"); for (int i = 0; i < 250; i++) { // make the calibration take about 5 seconds qtr.calibrate(); Serial.print("."); delay(20); } Serial.println("done qtr calibtation"); qtrPosition = qtr.readLine(sensors) noLine0=sensors[0]; noLine1=sensors[1]; noLine2=sensors[2]; //*****************************

//this is in the part where the robot is moving, I want it to look for a line and if found to follow it qtrPosition = qtr.readLine(sensors); if (sensors[0] > noLine0 || sensors[1] > noLine1 || sensors[2] > noLine2) { //see a line? doLineRead();

void doLineRead() { qtrPosition = qtr.readLine(sensors); while((sensors[0] > noLine0 || sensors[1] > noLine1 || sensors[2] > noLine2)) { qtrPosition = qtr.readLine(sensors); myMotor1->setSpeed(motorRight); myMotor2->setSpeed(motorLeft); error = qtrPosition - 1000; if (error < -500) // the line is on the left myMotor2->setSpeed(0); // turn left if (error > 500) // the line is on the right myMotor1->setSpeed(0); // turn right } }

It’s very rough but this is what I have so far. Thanks!

Are you moving your robot back and forth over a black line while the calibration routine is running? If so, I am a little worried that your calibration routine ends immediately before you execute readLine() and record noLine0, noLine1, and noLine2. Are you moving your robot to a space not on a line before the end of the 5 seconds it takes your calibration routine to run?

If you post a video that shows you calibrating your robot and how the robot follows the line, that might help me see what is going wrong.


No, not moving it over a line while calibrating. I was doing the calibration where there was no line. Maybe that’s the problem?

The calibration routine is designed to expose the QTR sensors to the full range of surfaces in the robot’s environment so the maximum and minimum reflectance values can be stored and used to compare to other readings later. If you run the routine without moving each sensor directly over the line and directly over an empty space, the robot never stores the value of reflectance that should correspond to a black line. To calibrate correctly, you can repeatedly move the robot back and forth from one side of the line to the other during the five second delay.