Basic Follow The Line Step By Step NXT Robot

Lego MINDSTORMS NXT
Basic Line Follow Step By Step Directions

Line following works by using the Light Sensor to read the changes in reflected light level along the edge of a dark and light surface.   Then the Switch Block directs the motors to vary the speeds depending on the Light Sensor Value.

In a Basic Line Follow the Light Sensor reads the light value.  If the value reads darker than a set value the left wheel spins and the right wheel stops.  If the value reads lighter than the set value the right wheel spins and the left wheel stops.  

The pseudo code for Basic Line Follow Reads as:

Loop(forever)
if LightValue < 40
LeftMotor Power = 40
RightMotor Power = 0
if LightValue > 40
RightMotor Power = 40
LeftMotor Power = 0

 

Robot Project 1b:  Basic Line Follow

Objectives:
Use Conditional Switch Block to evaluate Input Values of Light Sensor
Use Loop Block to Repeat Switch Block

Project:
Write an NXT-G program that will have your robot follow a line using a simple Algorithm.

Process:

1.  Open the Mindstorms NXT-G software.  (Double click the orange square icon.)

2.  Name your program “LastnameBasicLineFollow” and Click “GO.”

3.  Drag a Switch Block to the Programming Area.
a. Set the Sensor to “Light Sensor”
b. Set the Compare to < 40.

4.  Drag a Motor Block to top inside of the Switch Block

5.  Set the Motor Block Parameters to:
a. Motor Selection = C
b. Power = 40
c. Duration = Unlimited

6.  Drag another Motor Block and put it on the top inside of the Switch Block.

7.  Set the Motor Block Parameters to:
a. Motor Selection = B
b. Direction = Stop

8.  Drag another Motor Block and put it on the bottom inside of the Switch Block.

9.  Set the Motor Block Parameters to:
a. Motor Selection = B
b. Power = 40
c. Duration = Unlimited

10.  Drag another Motor Block and put it on the bottom inside of the Switch Block.

11.  Set the Motor Block Parameters to:
a. Motor Selection = C
b. Direction = Stop

12.  Drag a Loop Block into the programming area place it to the left of the Switch Block.

13.  Drag the Switch Block inside the Loop Block.

14.  Save Program.  (File -> Save)

15.  Download and test with the Robot.

Notes:
A.  You will need to work with the Light Value Numbers and Motor Speeds to “tune” the line follow to track the line depending on light conditions and path of line.  A lower motor speed will allow the robot to track a “more curvy” line.

B.  This program will track the Right Hand side of the line.  How can you change the program to track the Left Hand side of the line?

C.  The robot makes a wiggly track to follow the line.  How can you modify the program to allow for more efficient motion with the Robot.

Leave a Reply

Your email address will not be published. Required fields are marked *