In addition, I would examine the measurement range of the color sensor.
In a state which floated from the floor about 2cm, I measure with a ruler the range of illuminated LED. But shifted red, green and blue position slightly, like a range that is lit approximately 3cm in diameter.
In other words, the extent of the LED light will be about 70 degrees. It is more perfect the object is in this range can be transmitted to the light sensor of the LED. When you are measuring 2cm in front of the sensor, the size of the object is about 3cm. The object is small or away from the sensor, it could not properly detect the colors.
If you wish to detect the color of the size of one block, the object would be better close to about 1cm in front of the sensor. And around the sensor is in the dark as much as possible, rather not light comes from the outside.
In the end, I want to measure the time to detect by the color sensor. The reason I would measure the time, because the speed is the most important to use the sensor in robot competitions.
It is a program that was created (Program-3.rbt). Use the loop block, to run about 1000 times, the timer is divided by 1000 at the end. This should be obtained the one-time loop.
When you run the program, "1.096 msec (milliseconds)" are displayed in the LCD. This is the time per measurement. It will be 1000 รท 1.096 = 912.40 ..., in other words, "that can be measured 912 times per second."
As a result, it was found out the color sensor is many times faster compared to the ultrasonic sensor.
I introduced you to the basic performance of the color sensor this time. Next time, will introduce in more detail how to take advantage in making robots.
[DOWNLOAD] program which was made this time (recommended for LEGO Mindstorms NXT2.0 Education or higher)