Line Follower






Name of Activity

Line Follower




car, light sensor, line, follow, loops, loop, ports

Subject and Grade Level

NXTs, 4, 5, 6, 7, 8, 9+


1 Hour Total

Lesson Objectives:

– To learn to program using light sensors

– To learn to program using loops

– To practice building with an NXT kit

Materials Needed:

– NXT Kit

– Solid colored floor or mat

– Tape that contrasts floor or mat

– Planning and Final Design Worksheets

– Computers running MINDSTORMS NXT-G Software

Preparation and Set Up:

– Set up a line for students car to follow

– Set up computers running NXT software

– Photocopy worksheets

– Arrange students in groups of two

– Distribute necessary materials


  1. Have students plan out their design and program on paper before distributing materials. Help students think about the program by asking the following questions: How can the light sensor help you detect the line? What should happen when the car senses the line? What about when the light sensor detects the floor again? What is a loop? How will a loop be helpful in your program?
  2. Have students build cars using NXT-G kits, or provide a pre-built car to each group.
    1. The light sensor should be pointed at the ground.
    2. Make sure the car can easily turn by attaching a skid plate or attaching a swivel wheel to the front of the car.
    3. Attach the light sensor to the front of the car.

  • Have students program their cars.
    1. The car should follow a line using a light sensor.
    2. Program one motor to turn until the light sensor detects the line.
    3. Use the “Wait for” block to use the light sensor data.
    4. When the light sensor detects the line, have the first motor stop and the other motor turn until the light sensor detects the floor, at which point the second motor will stop.
    5. Insert a loop around the program so that the car continually follows the line.

  • Allow students to test their design on a tapeline on the floor.
  • Tell students that they may redesign their car as this is an important step in the Engineering Design Process.
  • When students have completed their cars have them fill out their final design sheets.
  • Gather students together as a class and let each group share their car. Discuss the activity as a class.
  • Extensions or Modifications:

    – Create a theme for the project such as “rounding the bases” so that the students cars have to do more than just follow a line.

    – Have a challenge at the end of the line. For example, at the end of the line there is a box that the NXT car must pick up. Students must design a robotic arm to lift the box.

    Sample Image 1

    Sample Image 2

    Sample Image 3

    Sample Image 4

    Sample Image 5

    1 comment on this post.
    1. Leah E. Fletcher:

      We did this activity in a 4th grade classroom as a “Lava Line Follower.” We brought in sheets of paper with lines of duct tape, where one side was safe, and the other side of the line was lava. The car wanted to get as close as possible to the lava without going in. The students were very interested in the activity, but were confused by the concept of Switches in the programming in Mindstorm. We extended it to a second class period to better explain switches.

    Leave a comment

    You must be