The Color sensor uses reflected light to detect an object’s color, hue value, grayscale value, brightness, and proximity.
The VEX IQ Color Sensor is included in the VEX IQ Super Kit and can also be purchased here.
Using a 2nd Generation VEX IQ Robot? See an overview of 2nd Generation sensors here, and information on the Optical Sensor, the 2nd Generation version of the Color Sensor.
Description of the Color Sensor
The VEX IQ Color Sensor has multiple modes, which allow it to capture different types of information from its environment. The information it collects is affected by the lighting conditions of its environment as well as the distance between the sensor and the object or surface it is reading.
How the Color Sensor Works
The Color Sensor can detect both color and proximity.
Detecting Colors
When in brightness mode, the Color Sensor is used to detect the intensity of all light in the robot’s environment. The more light that reaches the Color Sensor while it's active, the higher the percentage value sent to the Robot Brain.
If the detected brightness percentage is low or unreliable, the Color Sensor’s lamp can be turned on or the lamp’s brightness percentage can be raised by using the following set light to block:
The Color Sensor can report the color it sees as either a color value or as a hue value.
Color values. There are 14 listed colors that the Color Sensor can detect. The colors missing from the image of the block are red, green, blue, white, and yellow.
Hue values. Hue values are like color values but numerical. The hue value ranges from 0 to 360, like degrees. The color values listed above have their own equivalent hue value ranges.
It is important when detecting colors and hues that the Color Sensor have the proper amount of light to do so. Be sure to test, also known as calibrating, your Color Sensor in different levels of light and with the lamp set at different levels to determine which is the most reliable setting for your robot’s Color Sensor.
Detecting Proximity
The Color Sensor includes an infrared sensor-emitter. The infrared emitter shines an invisible light and then detects its reflection. If most of the infrared light bounces back toward the sensor, it tells the Robot Brain that an object is close.
Common Uses of the Color Sensor
Color sensors are used in many technology applications where having specific colors on displays or products is important.
Some common uses in daily life include:
- Color calibration tools check if a digital screen is displaying accurate colors, and then adjust the display settings as needed. It is important for graphic artists and any designer who works with color on a digital screen to be able to see exactly the correct color being displayed. Misunderstandings and wasted resources result when the colors are not accurate.
- Cameras and camcorders use color sensors to adjust settings based on the lighting conditions they are in, in order to enhance their photos and videos by maximizing light levels and enhancing otherwise dull colors. These sensors also allow a photographer to focus on specific colors in their photos.
- Color sensors are sometimes used in manufacturing, to quickly inspect if a product has the correct color before it gets shipped to a customer. For example, fruits and vegetables that turn colors when ripe or ready to be eaten can be scanned to ensure that they are the correct color to send to market.
Some common uses with a VEX IQ Robot include:
- This sensor can be used to detect the color of an object.
- This sensor can be used to detect and/or follow a line.
- This sensor can detect whether an object is near.
Color Sensors on a Competition Robot
Remember, it is important when detecting colors and hues that the Color Sensor have the proper amount of light to do so. Be sure to test, also known as calibrating, your Color Sensor each time you arrive at a new competition site because different levels of light can affect how your Color Sensor performs. Test your project with the lamp set at different levels to determine which is the most reliable setting for your robot’s Color Sensor.
The information collected by the Color Sensor is useful for programming a competitive robot to respond to a variety of conditions. The Color Sensor can make a competition robot better in the following ways:
- It lets the robot detect the color of an object near the sensor. This is useful if you want the robot to sort differently colored objects, drive up to a specifically colored object, or detect the color of objects as they pass by the sensor.
- It lets the robot detect how much light is reflected back into the sensor. This allows your robot to drive until it reaches a line on a surface, or even to follow a line.
- It lets the robot know whether an object or surface is near. This is helpful in determining whether a detected color is a reading from a nearby object or potentially, an anomalous reading of a distant surface or light.
Coding the Color Sensor in Blocks
The <Found an object> block is a Boolean reporter block that reports a condition as either true or false. Boolean blocks, like the <Found an object> block fit inside blocks with hexagonal (six-sided) inputs for other blocks.
The <Found an object> Boolean block reports 'true' if the 'true' if the Color sensor detects an object, and 'false' if the sensor does not. To learn more about Boolean blocks visit the Help or the Block Shapes and Meaning article.
In this example, the <Found an object> block is used to detect proximity along with a [Wait until] block, to make the robot drive forward until an object is detected.
The <Color detects> block is also a Boolean reporter block that reports a condition as either true or false. The <Color detects> block reports 'true' if the 'true' if the Color sensor detects the selected color and 'false' if the sensor detects any other color. To learn more about Boolean blocks visit the Help or the Block Shapes and Meaning article.
In this example, the <Color detects> block is used along with a [Wait until] block to cause the robot to drive forward until the Color Sensor detects a green object. The robot will then stop driving. This is illustrated in the first video above.
The (Brightness of) block reports the amount of light detected by the Color Sensor. It is a reporter block used inside other blocks with circular spaces.
The (Brightness of) block reports a range of 0% to 100%.
In this example, the (Brightness of) block is used to have the robot detect and follow a line, as shown in the second video above.
The (Hue of) block reports the hue of the color detected by the Color Sensor. It is a reporter block used inside other blocks with circular spaces.
The (Brightness of) block reports a range of 0 to 360.
In this example, the (Hue of) block is used to have the robot check a range of hue values that correspond to the color red, and to turn right for 90 degrees if those values are detected by the sensor. If any other hue values are detected, the robot will turn left for 90 degrees.
The (Hue of) block can be useful when it is necessary for the robot to detect certain colors when ambient light conditions may be inconsistent.
Coding the Color Sensor in Python
Note: To code an VEX IQ (1st generation) Bumper Switch in Python, it must be connected to a VEX IQ (2nd generation) Brain. The VEX IQ (1st generation) Brain does not support Python.
The color.is_near_object command reports True when a Color sensor detects an object or surface close to the front of the sensor and False when a Color Sensor does not detect an object or surface close to the front of the sensor.
Note: The name of the Color Sensor that appears in the command corresponds to the name it is given in the configuration.
In this example, a While loop with a not condition is used with the color.is_near_object command to make the robot drive forward until the the Color Sensor detects an object close to the front of the sensor.
The color.color command reports the color currently being detected by the Color Sensor.
In this example, a While loop with a not condition is used with the color.color command to make the robot drive forward until the Color Sensor detects a green object. The robot will then stop driving. This is illustrated in the first video above.
The color.brightness command reports the amount of light detected by the Color Sensor. It reports a range of values from 0% - 100%.
In this example, the color.brightness command is used to have the robot detect and follow a line, as shown in the second video above.
The color.hue command reports the hue of the color detected by the Color Sensor. It reports a range of hue values from 0 to 360.
In this example, the color.hue command is used to have the robot check a range of hue values that correspond to the color red, and to turn right for 90 degrees if those values are detected by the sensor. If any other hue values are detected, the robot will turn left for 90 degrees.
The color.hue command can be useful when it is necessary for the robot to detect certain colors when ambient light conditions may be inconsistent.