Colour Sensor Block

The Colour Sensor block gets data from the Colour Sensor. You can measure the colour or intensity of light and get a Numeric output. You can also compare sensor data to an input value and get a Logic (True or False) output.

See Using the Colour Sensor for more information about how the Colour Sensor works, the different modes, the data provided, and programming examples.
Tips and Tricks
The Colour Sensor block outputs data with a Data Wire See Using the Colour Sensor for other ways to use the Colour Sensor that don’t require a data wire.
Choose the Sensor Port and Mode



Port Selector
Mode Selector
Inputs
Outputs

Use the Port Selector on the top of the block to make sure that the sensor port number (1, 2, 3, or 4) matches the port on the EV3 Brick that the Colour Sensor is connected to.

Use the Mode Selector to select the mode for the block. The Inputs and Outputs available will change depending on the mode.
Modes
Measure - Colour


The Measure – Colour mode outputs the detected colour number in Colour.
Measure – Reflected Light Intensity


The Measure – Reflected Light Intensity mode outputs the light intensity in Measured Value.
Measure – Ambient Light Intensity


The Measure – Ambient Light Intensity mode outputs the light intensity in Measured Value.
Compare – Colour


In the Compare – Colour mode, you can select one or more colours in the Set of Colours. The Compare Result output will be True if the detected colour matches any of the selected colours. The detected colour is output to Measured Value.
Compare – Light Intensity


The Compare – Reflected Light Intensity and Compare – Ambient Light Intensity modes compare the detected light intensity to the Threshold Value using the selected Compare Type. The True/False result is output in Compare Result, and the detected light intensity is output in Measured Value.
Example 1
This program turns the Brick Status Light on in orange, and makes it pulse on and off whenever the Colour Sensor detects an ambient light intensity greater than 50.
Example 2
This program makes a robot drive until the Colour Sensor detects reflected light intensity < 50, or until motor B has turned 2000 degrees, whichever comes first.
Calibrate Modes
The Calibrate modes allow you to calibrate the Colour Sensor from within a program. You can also manually type in the minimum and maximum value the sensor should use.
Calibrate - Minimum


The Calibrate – Minimum mode allows you to specify the minimum light intensity in the Value input. After calibration, the Colour Sensor will report this light intensity as 0 or the value specified.
Calibrate - Maximum


The Calibrate – Maximum mode allows you to specify the maximum light intensity in the Value input. After calibration, the Colour Sensor will report this light intensity as 100 or the value specified.
Calibrate - Reset


The Calibrate – Reset mode restores the Colour Sensor calibration to its default state.
Inputs and Outputs
The inputs available for the Colour Sensor block will depend on the mode selected. You can enter the input values directly into the block. Alternatively, the input values can be supplied by Data Wire from the outputs of other Programming Blocks.
InputTypeAllowed ValuesNotes
Set of Colours Numeric ArrayEach element: 0 – 7Selected colour(s) to test for in Compare – Colour mode:
0 = No Colour
1 = Black
2 = Blue
3 = Green
4 = Yellow
5 = Red
6 = White
7 = Brown
Compare Type Numeric0 - 50: = (Equal to)
1: ≠ (Not Equal to)
2: > (Greater than)
3: ≥ (Greater than or Equal to)
4: < (Less than)
5: ≤ (Less than or Equal to)
Threshold Value NumericAny numberValue to compare sensor data to
Value Numeric0 – 100Light intensity for Calibrate modes
The outputs available will depend on the mode selected. To use an output, use a Data Wire to connect it to another Programming Block.
OutputTypeNotes
Colour NumericDetected colour number:
0 = No Colour
1 = Black
2 = Blue
3 = Green
4 = Yellow
5 = Red
6 = White
7 = Brown
Compare Result LogicTrue/False result of a Compare mode.
Measured Value NumericThe sensor data value used for a Compare mode.
Colour
Quick links