Line Following with NXT 2.0

I have received a lot of questions and requests about line following over the last several months. Some requests are coming from the FLL direction and such, but also users of the NXT 2.0 retail kit are wondering how to do line following using the color sensor, which is somewhat harder and/or less obvious than with the (NXT 1) light sensor.

So I have posted this NXT 2.0 Line Follower project to show two ways to do this (there are many other approaches), a simple "Two State" line follower program, and a more complex "Proportional" line follower, which is smoother and faster. In addition, the Proportional version includes an automatic calibration sequence, where the robot automatically scans the line and surface to determine the minimum and maximum expected brighness values on its own. These programs will only work on NXT 2.0. I will follow up with some info and programs for NXT 1.0 users later.

Although under good conditions you can make a simple line follower using the color sensor in "Color Sensor" mode (if it will read, say, black for the line and white for the floor), you are better off using the color sensor in "Light Sensor" mode, where you can get a numeric brightness value from the sensor, so both programs here use it this way. However, two complications arise out of using the color sensor in Light Sensor mode. First, "calibration" of the sensor (determining the minimum and maximum expected light values) is not supported by the NXT software. The Calibrate Sensors menu command as well as the Calibrate programming block only support the original (NXT 1) light sensor, not the color sensor in Light Sensor mode. So you need to do your own calibration. But then the other issue is that the "View" feature on the NXT brick menu (e.g. View Reflected Light) again only supports the old light sensor (the View Color choice will only show the color sensor in color sensor mode). So while doing your own calibration, you will also want to use your own program to do this.

To keep the simpler line following program as simple as possible, the "Two State" line follower program requires you to sample the light values and modify the program as necessary. As a tool to help with this and similar uses, I have posted an NXT 2.0 Light Meter project (you can use just the program if using it to calibrate another project such as the Line Follower). The Light Meter program also allows you to change the sensor option of red/green/blue/ambient, which makes it interesting for other experiments as well.

As a more advanced approach to the issue of calibration, the "Proportional" line follower also includes an automatic calibration sequence to eliminate the need to calibrate manually or modify the program based on the conditions.


wow that is one of the fastest single light sensor line followers I have ever seen. It barely wiggled! My fastest single sensor was a good speed but it wiggled a lot :P now I just use the lineleader but even that wiggles a little in nxt-g
Len said…
Is that electrical tape you used to make the line?
Dave Parker said…
Yes, electrical tape is flexible enough that with a little practice you can make curves without wrinkles, or cut it if you need tighter turns. It also comes up easily leaving no residue.
varmie said…
Dave.....won't download to the nxt..error message 5002
Anonymous said…
fantastic line follower.can it follow a figure 8 pattern?
thanks for your help.
Unknown said…
Did you ever post the NXT 1.0 information for proportional line follower? If so can you forward me the link? Thank you for your help.

Philip Martin
janie said…
My robot needs to follow a line in a W formation. It gets stuck in the tight inside turns. Can you help?
Unknown said…
I have made a program that does the following :
(switch block )If the color sensor detects a black strip on the floor , the robot stops .If not , use the light sensor for line following ( LineFollow5 from NXT ). Then I put the switch in a forever loop , but when I run the program it just spins backward around itself !!! I have calibrated the light senor but nothing happened .What shall I do ? Plz reply ASAP .Thanks !
Unknown said…
do you still have the code

Popular Posts