Let's Make Robots!

RPR220 distance

RPR220 detect black line, problems with distance

I want to detect the black line with RPR220 when building a line tracker. I connect the rpr220 output to a LM311 the comparator.but when it can detect the black line when the distance between RPR220 and the line is 2.5cm,it cannot do it correctly with the distance 1.5cm. And recognize the black line as the white background .

the voltage on the collector of RPR220 can clearly distinguish black and white at a certain distance, but cannot do it if the distance is closer ,why is that?