The color sensor can detect 12 preset colors or a color you it uses the same color names as the touch LED. The color sensor can also detect grayscale, which is actually light intensity, and the proximity of a color. Before we use the color sensor, we need to decide on one of three color modes, which we set in the motor and sensor setup. For this example, we will use color name and make the robot stop once it detects read, you might see that I had some trouble detecting red and so I added another color, red violet and the OR operator to increase the range of red colors it will detect. The color sensor can also detect whether a color surface is near or far doesn't give a precise reading like the ultrasonic sensor, but one could use it to detect an obstacle. This example program will display whether the color it detects is near or far on the screen.
It will also display the actual c sensor reading on another line. Now let's use the use scale to detect colors. This sample program will display the color that the sensor detects on the brain screen by reading the color you because all sensors are a little different, it would be better if you check the census value in the debugger window. This will help you set a range of values for each color. Hold the sensor over a color and note the reading. Then set the ranges above and below that reading for each color.
Do take note that red is on both ends of the scale