I am trying to build an advanced coloured lines following robot with the ability to differentiate between many different coloured lines and follow them. I am looking for the right sensor that will help my robot achieve its objective.

As I was researching I came across the EV3 Colour Sensor which can detect up to 7 colours.

Is this sensor suitable for my project?

What other sensors can I use and how?

Thank You

  • $\begingroup$ Are the lines going to have hard turns (like right angles) or will it be curvy? I've always used multiple sensors on the bottom, the more the merrier, so buy multiple $\endgroup$
    – Tom Prats
    Commented Dec 9, 2013 at 16:17
  • $\begingroup$ I would imagine that the answer to this question depends heavily on the width of the lines that you'll be following, and how close the sensor needs to be in order to sense the color (vs sensing a combination of 2 colors). $\endgroup$
    – Ian
    Commented Apr 16, 2015 at 18:08

3 Answers 3


The EV3 Color Sensor will work great if you're using the Mindstorms platform, if not it will be a pain it uses a non standard connection style and a not quite standard I2C communication protocol. If you are using an arduino then I would recommend something like this from sparkfun which still uses the I2C bus but will be far easier to integrate into a project.

In order to use it you will have to profile the color of the lines you want to follow in the exact same conditions that you will use for your robot to get best results.

  • 1
    $\begingroup$ The EV3 Color Sensor is not I2C at all. It uses UART with a custom protocol. See ev3.fantastic.computer/doxygen/UartProtocol.html $\endgroup$ Commented Jul 7, 2015 at 18:59
  • $\begingroup$ Then I stand corrected, the NXT color sensor was and I was under the impression that the EV3 one was as well $\endgroup$
    – Mark Omo
    Commented Jul 7, 2015 at 19:00

I hope you can only use EV3 Color Sensor for line following and sensing colors. There are 3 modes for the Color Sensor. You can use 2 of them for these tasks:

1.) Color Mode This mode is best suited for sensing colors. This is really useful if the darkness of the Colors are same. It can only sense a handful of Colors: Black[1], Blue[2], Green[3], Yellow[4], Red[5], White[6] and Brown[7]. If you don't want to make your Robot follow the line precisely you can use this mode.

2.) Reflected Light Intensity This is used to determine the reflection of the surface. This is very useful if you want to make your Robot follow the line precisely. Let's say if you want your Robot to follow in between the black line and the white line. You can get the reflected values of the white surface and the black surface and add them and dividing them by 2 will give the threshold value to make your Robot follow in between the black and white line. It is generally used to measure the darkness of a surface. The more darker the surface,lesser is the reflection. The more brighter the surface, more is the reflection.

Unfortunately you can't use both the modes simultaneously in EV3 as it will result in resource conflict letting your Robot to crash. Instead you can use 2 Color sensors to use both the modes simultaneously in each sensor.


The EV3 color sensor can easily be used to follow different colored lines (e.g., red lines, green lines, blue lines). The important part about using the sensor is selecting the proper mode for following the particular colored line. For example, if the line is just a black line on a white background, then set the sensor to reflected light. However, if the line is a colored line (red/green/blue/other), then set the sensor to RGB Color mode which will output three numeric values (r, g, b). Each numeric value will range from 0% to 100% of that color. If the colored line is on a white background, then the percentages of the various colors may range from 100% to 50% or lower depending on how much of the sensor is over the line. For example, if it is a red line, then the red value from the sensor will be 100% regardless of whether the sensor is over the red line or white background. This is because the white background will generate a value of 100% for each RGB color. If the red line is over a black background, then the value for red will vary between 100% (over the red line) to 0% over the black background. So, if the line is red and the background is white, how do you follow the line since the sensor will only show 100% red? The answer is to use one of the other values from the sensor (e.g., green or blue). If the line is red and the background is white, then use the blue value from the sensor which will show 0% when over the red line and 100% when over the white background.

For example programs about using the EV3 sensors for line following, and detection and for examples about detecting colors, see: https://robotjavascript.com/line-following-examples.htm and https://robotjavascript.com/sensor-examples.htm#colorSensorValue

These examples are written in Robot JavaScript. The colorSensorValue() function returns an object with three numeric properties: { r: [0-100] , g: [0-100], b: [0-100] }

To follow the line, use the syncMotors() function and set the steering parameter to your desired sensor value: colorObject=colorSensorPct(); syncMotors(2, 3, constantPower, gain*(colorObject.b-target)); Then all you need to do is adjust the constantPower, gain, and target for your particular needs.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.