I have to build a line following robot that will be able to detect a selected colored line on the floor and start following it.

How do color sensors do this after detecting the specific colored line?

  • $\begingroup$ It is not clear from your question, do you want to follow a black line on a white floor, or do you actually want to determine the color of the line? And if so, what kind of accuracy do you want (3 colors, 10 colors...)? (Following black electrical tape on a white floor is a pretty standard example problem in robotics). $\endgroup$
    – Ben
    Feb 21, 2014 at 20:49

3 Answers 3


It seems like you are asking how to do the line following, so here's one way to think about it:

Once you have found the line, one way to follow it is to follow one of the edges of the line. For example: following the right edge could be done like this:

If you have two color sensors (left and right) and the left sensor is on the line while the right is not, continue forward.

If the right sensor or both sensors detect the line, turn right slightly until the robot is back on the right edge.

If the left sensor doesn't detect the line and the right doesn't detect the line, the robot has gone off the right side of the line. Turn left.


This is a common problem in First Lego League, and, while legos are simple, the approach would hold for many other environments. Here is a video showing a way to follow the middle of the line using two color sensors. And here is an article showing the principles of how to do it.

In short, the algorithm is like this (assuming you are following the right side of the line)

  1. Calibrate the difference in color between "the line" and "not the line"
  2. As you drive, continually measure the color, assume you should be measuring half way between "the line" and "not the line".

    1. If the measured color is closer to "the line" then you are too much on the line and need to steer away from it. the line.
    2. If the measured color is closer to "not the line" then you are too far off the line, and need to steer towards it.

It might require a little bit of soldering to create such a color sensor, but you can probably handle it.

The easiest way to create a color sensor for such an application is by using a reflective optical sensor such as the following: Optical Sensor

It is basically just a light detector and a LED. The light emitted from the LED gets reflected by the surface and hits the detector.

The amount of reflected light is dependent on many things, but mainly on the color of the surface. If the surface is black all the light will be absorbed and the detector won't see any light. If the surface is white the detector will see a lot of light and so on.

Image i found on google images

To create an linetracking sensor for the robot i suggest that you use several (e.g. 6) of these sensors and place them pointing downwards on the front bumper of the robot. You can now detect where the line is by looking at the individual sensors and detecting which one (or more) sees less or more light.

This will give you a relatively cheap sensor that should be sufficient for a line tracking robot.

The downside is however that it requires a bit of soldering. On google i have found the following diagram that you might use.


  • $\begingroup$ The question is asking to to use a colour sensor for line following, not how to make a monochrome sensor. This is a colour sensor, uk.farnell.com/kingbright/kps-5130pd7c/… or you can get modules for breadboarding. $\endgroup$ Jul 21, 2017 at 9:41

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.