Knowledge Base

Color Sensor

The EV3 Color Sensor is used to detect colors or light intensity. The sensor is very useful for both line following and obstacle detection. 

Facing down, towards the surface, the Color Sensor can distinguish between 7 colors or measure the intensity of the reflected light, making it ideal for line following. By emitting its own light, the sensor can work even in absolute darkness to determine the color or brightness of the surface. 

When facing forward, the light intensity will change when nearing an obstacle. This behavior of the Color Sensor is used for obstacle detection, turning the Color Sensor into a proximity sensor. Note that this will work only for short distances of 2 cm or less between the sensor and an obstacle. For greater distances, we recommend using the Ultrasonic Sensor.

The Color Sensor block supports two methods:

  • get.ColorID - Used to identify colors, the ColorID method will return a different number for each detected color. The color ID's are as follows:
Color ID
Black 1
Blue 2
Green 3
Yellow 4
Red 5
White 6
Brown 7

Note that the color sensor cannot identify all colors and may stray when confronted with unassigned colors. 

  • get.Red - Used to measure the intensity of the reflected light. Since black absorbs light while White reflects it, the returned value can distinguish between bright and dark colors. Dark colors return values as low as 0, while bright colors can return values as high as 100. This makes the Color Sensor getRed method ideal for line following using Proportional or PID control algorithms.

You can also use the Wait Until block to pause the code until the robot detects a specific color or crosses a certain threshold.

 

In this example, the robot will drive forward for as long as the Color Sensor is over a bright surface:

The program will also print to the console the current light intensity value (0-100).

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

Please sign in to leave a comment.

Powered by Zendesk