QTR sensor's enviroment light influence

Hi Everyone,
I need some help and guide from you about the QTR sensor’s using on 3PI.
Now I’m running the PID follower by 3PI hardware. I can now smooth running by an good enviroment light condition so that we could set the PWM speed even more than 160.
But when I turn to an worse light condition, 3PI can not work correctly any more although I had already use the standard calibration routing.
The appearance is that all the sensor’s value jump from max to min very frequently so that the position will also accordingly not stable any more(sometime 0,sometime 4000)!!!
My question is why it will happen? Because 3PI’s QTR has their own IR emitter,why still will be influence by enviroment light?
Then which I had an investigation on the routing of “PololuQTRSensors::readLine” ,found that it had already include some on/off line condition,can I improve this or how can I improve my 3PI car on poor light condition?

[code]unsigned int PololuQTRSensors::readLine(unsigned int *sensor_values,
unsigned char readMode, unsigned char white_line)
unsigned char i, on_line = 0;
unsigned long avg; // this is for the weighted total, which is long
// before division
unsigned int sum; // this is for the denominator which is <= 64000
static int last_value=0; // assume initially that the line is left.

readCalibrated(sensor_values, readMode);

avg = 0;
sum = 0;

for(i=0;i<_numSensors;i++) {
	int value = sensor_values[i];
		value = 1000-value;

	// keep track of whether we see the line at all
	if(value > 200) {
		on_line = 1;
	// only average in values that are above a noise threshold
	if(value > 50) {
		avg += (long)(value) * (i * 1000);
		sum += value;

	// If it last read to the left of center, return 0.
	if(last_value < (_numSensors-1)*1000/2)
		return 0;
	// If it last read to the right of center, return the max.
		return (_numSensors-1)*1000;


last_value = avg/sum;

return last_value;


The IR sensors should work in darkness, if the emitters are working right.
Can you test whether the emitters are working somehow? Do you have an IR camera? Or can you point a cheap webcam or cell phone at the emitters in darkness to see if they flash? (you can verify whether your camera can read IR by testing with a TV remote while you’re holding down the volume-down button.)

Very impressive,jwatte!
Now I can check the IR emitters as normal LED.
1.IR emitters is working well even under darkness!
2.For some black track (Smooth surface which will light reflective), do not use the calibrated value to judge the cross road.
3.Use un-calibrated value will better to judge the cross road(seems some sudden unexpected reflective will easily exceed calibrated max&min).
Welcome any suggestion to my updating!


Although the 3pi has its own IR emitters, the IR detectors can be affected by other IR sources (e.g. sunlight). If you continue to have problems, you might try adding a shield that blocks off all other light sources from the sensors.

- Jeremy