The Lego motor is controlled using a feed back mechanism to influence the pulse width modulation.
On the shaft of the motor the rotation speed is measured. This measurement is used to control the power to the motor or rather to modify the width of the PWM pulse. If for some reason the motor slows down (for example because you’re pinching the axis with your fingers) the PIC will increase power to the motor until the speed reaches it’s set point again.
Main difficulty in this project is the deviation between the real world and mathematical PIC precision. The first challenge is how to get a feedback signal. I took one of the Lego wheels and glued a piece of paper with 50% black and 50% white on it. As a sensor the Fairchild QRB134 infrared photo reflector was used. It is equipped with a special daylight filter so it pretty much reacts to it’s own (infrared) light only. And it is conveniently small (2/3 of a brick high). Being Dutch the price (1.50 $US) is quite nice too. The data sheet is not at all clear about the way it should be connected, so I fried the first one because I thought the resistor was integrated.
Visit Here for more.