Case 10 - Line Detection with Line Follower Sensor

Case 10 - Line Detection with Line Follower Sensor

 

Part 1   Objective

After you compile the program, you can use the line follower sensor to detect the line color, and then control the rotation of the motors. Usually, the motors rotate when the line is black, and they stop rotating when the line is white.

36.gif

Part 2   Preparation

  • MegaPi x 1

  • MegaPi RJ25 adapter x 1

  • MegaPi encoder/DC motor driver x 2

  • Line follower sensor x 1

  • RJ25 cable x 1

  • Photoelectric encoder motor 185RPM with wheel x 2

  • Encoder motor cable x 2

  • USB cable (Type-B) x 1

  • Battery holder with 6 AA batteries x 1

  • Computer with network access x 1

Install the MegaPi RJ25 adapter and the MegaPi encoder/DC motor drivers on MegaPi, connect the line follower sensor to MegaPi by using the RJ25 cable, connect the encoder motors to MegaPi by using the encoder motor cables, connect the battery holder to MegaPi, connect MegaPi to the computer by using the USB cable, open mBlock 5 (PC client, web version, or mobile app), click +add, select Ultimate 2.0 from Device Library, click Connect, and select the Live mode.

37.gif
38.gif

Part 3   Programming

Line detection with line follower sensor: Use the if ( ) then ( ) block for judgment. When the two probes of the line follower sensor detect black, it indicates that Ultimate is moving along the line and the motors rotate normally (meaning Ultimate moves forward). If none of the two probes detects black, it indicates that Ultimate is not moving along the line and the motors stop rotating.

39.gif

Part 4   Practice

Try to change the line color, making the motors rotate when the line follower sensor detects white and making them stop rotating when the line follower sensor detects black.

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.