I'd like to check the outer diameter of the screw, but I wonder if the reflected light from the metal surface causes sensor malfunctions. Screws that have less than ten milimeter in diameter are not good and the tolerance should be within 0.2mm. Do you have any good ideas?
How about using a fiber sensor that has a 0.1mm diameter beam spot? You set the beam spot on the edge of the outer diameter of the screw, and then if the beam returns the screw is good but if the beam doesn't return the screw is not good. Even if the object has a metal surface, a thru-beam type sensor that has a narrow beam spot can detect the object properly.