How to Program the Line Follower Bot

This lesson will go over how to program the Line Follower Bot

Line Follower Robot

What it Does

The Line Follower Robot is designed to follow a black line on a white surface.


Program the controller in such a way that:

  1. While left side sees white, turn right.
  2. While right side sees white, turn left.

Video Guide

How to Code

Firstly we need to setup our code. To do so we will include the SmartInventor library, setup our motors, and then set pins 13 and 16 (the bottom IR sensors just outside of the middle) as inputs.

Now it is time to write the main section of the code. In order to do so, a “While Loop” may keep the robot following the line. (Reminder! Click here to review how “While Loop” work).

Until the sensor associated with pin 16 (middle-left sensor) reaches the black line, the left motor must keep turning the robot to the right.

Until the sensor associated with pin 13 (middle-right sensor) reaches the black line, the right motor must keep turning the robot to the left.

The idea of this code is that it will keep wiggling back and forth above the line. Each time it wiggles it will move forward a little bit, thus letting it move along the line.

Caution: Make sure to calibrate the control properly by placing the robot on the line and adjusting the nob on the board until it distinguishes the difference between the line and the surface clearly.

Optional: In order to customize the robot’s actions, the motor speed or the delay time may be changed accordingly.

Final Code