Introduction: GoPiGo3 Line Follower

In this tutorial, we are taking a line follower and use it on the GoPiGo3 to make it follow a black line.

Step 1: Gathering the Hardware

There are a few things that we need before we start building our line follower:

  1. One of the 2 Dexter Industries Line Followers: either the Red Line Follower or the black one, slightly shorter. The black line follower is way more performant than the former.
  2. A battery pack for the GoPiGo3. We recommend using the Dexter Industries battery pack as it can keep the Raspberry Pi running even when the motors are going at full throttle.
  3. A GoPiGo3 - you only need a GoPiGo3 and that's it.
  4. Line Follower tracks - these can be downloaded from here.

Get the GoPiGo3 Raspberry Pi Robot Here!

Step 2: Build Your Track

This part is going to take a while. Basically, go here, download the PDF containing the templates, and print the following number of tiles in order for you to build the shown track or just build your own and skip this rather lengthy step:

  • 12 tiles of type #1.
  • 5 tiles of type #2.
  • 3 templates of tile type #5.
  • 3 templates of tile type #6 - here, you'll end up with one extra tile.

Next, cut and tape them and try to make them fit like in the above picture. Be aware that there's a tile on the top-right corner of type #1 that overlaps with another one of the same kind - that's how it is, so don't get confused when you see that.

Also, if somehow, the printer doesn't have enough toner and the black gets to be washed out, you might want to color the black lines with a marker to make them stand out for the line follower. It's not totally necessary, but it can make the line follower more precise.

Step 3: Choose the Line Follower

You have to choose what line follower you want to go with: the red one or the black one.

Regardless, the line follower has to be oriented just like in the above photo as described in the documentation too (ReadTheDocs documentation of DI_Sensors & GoPiGo3).

Step 4: Mounting the Line Follower

The line follower has to sit like that on the GoPiGo3. The Line Follower Kit from Dexter Industries comes with a few more things like spacers, nuts, and washers to help you fix it on the GoPiGo3.

Regardless of which line follower sensor you get, you will find 40mm spacers in your kit. So you can rest assured the space between the GoPiGo3 and the floor will be adequate (which is roughly 2-3 mm).

Note: In the above photo, you'll see that I have used some nuts to make the spacer even lengthier and that's because I'm not using the standard spacers that come in the Line Follower kit - mine are 30mm and they should have been 40mm.

Step 5: Calibrating the Line Follower

To calibrate the line follower, regardless of which one you are using, start with installing the appropriate libraries on the Raspberry Pi. You can do this on a Raspbian image or Raspbian For Robots. First of all, run these commands:

curl -kL | bash
curl -kL | bash

Reboot and then change the directory to


Then run the program in that directory like


Next, place the robot on a white surface (with the line follower attached and connected to the I2C port) and press on the appropriate button to calibrate it. You actually have to check the menu and see which button corresponds to "Calibrate the line follower on a white surface". Likewise for the black surface.

The project can be found on GitHub here.

Once calibrated, the values get stored even when the Raspberry Pi goes through a power cycle. It only needs to be re-calibrated when the line follower gets changed with the other on or when the track's colors change significantly.

Step 6: Setting the PD Gains

Optimal Values for the Line Follower

Using the appropriate buttons described in the menu, update the PD gains for the appropriate line follower that you are using.

Black Line Follower

For the new line follower, the following parameters work best for the GoPiGo3:

  1. Base Speed = 300
  2. Loop Frequency = 100
  3. Kp = 1100
  4. Ki = 0
  5. Kd = 1300

The Base Speed and Loop Frequency have to be changed directly in the code.

Red Line Follower

For the old line follower, the following parameters work best for the GoPiGo3:

  1. Base Speed = 300
  2. Loop Frequency = 30
  3. Kp = 4200
  4. Ki = 0
  5. Kd = 2500

The Base Speed and Loop Frequency have to be changed directly in the code.

Step 7: Following the Line - Black Sensor

Step 8: Following the Line - Red Sensor