Basic Line Following Robot With Arduino





Introduction: Basic Line Following Robot With Arduino

It has been a few years since we initially posted this Basic Line Following Robot with Arduino tutorial, and it appears so many people found it helpful that we should post an update which runs current Arduino Libraries, includes the newer robot kits that assemble faster/easier, and further explain some of these steps for those who may be very new to robots and Arduino.

In this tutorial, the goal and approach is the same as before. We are building and programming a robot that can follow a lined course with the use of an Arduino based micro controller system programmed to run a basic Proportional speed control. Proportional is a simpler and shortened version of a PID control. You can visit these Wikis to learn more about both systems :

Proportional Control


Updated 3/3/2017

Step 1: Build a Course...

Before you can run the Basic Line Follower, you will need a lined course. Use white poster board, foam board, white board, expanded PVC, or even a white floor or table and create a line course with black electrical tape. You may have sharp corners, but it will run smoother if the turns are gradual. Keep a minimum of 6" between any meandering lines.

Step 2: Robot Build List...

Zagros Robotics Start Kit - Magician Version (


Zagros Robotics Starter Kit - Gobbit Version (

Step 3: Robot Assembly...

After assembling the chassis per the chassis instructions, secure the battery, Arduino and Ardumoto shield to the chassis. For the Magician we used zip ties, the Gobbit has screws and Velcro included.

Next secure the QTR sensor so that it is just slightly above the driving surface. For the Magician we used thin wire so that it was easy to adjust the sensors position but strong enough to hold it, as it might take some adjusting. Try to set the clearance between the ground and the IR sensors (the little black boxes on the QTR board) about 1/8." Also take notice of the orientation of the sensor with the header pins towards the inside as noted in the wiring diagram in the next step. Otherwise, the sensor pins will not match the Arduino sketch and will run wild. The Gobbit has a predefined location for easily screwing the QTR in place which then maintains proper distance and orientation.

Step 4: Wiring...

A detailed wiring diagram can be found here:

Connect the following with the leads or jumpers :

  • Ardumoto Digital pin 2 - QTR Sensor pin1
  • Ardumoto Digital pin 4 - QTR Sensor pin2
  • Ardumoto Digital pin 5 - QTR Sensor pin3
  • Ardumoto Digital pin 6 - QTR Sensor pin4
  • Ardumoto Digital pin 7 - QTR Sensor pin5
  • Ardumoto Digital pin 8 - QTR Sensor pin6
  • Ardumoto Digital pin 9 - QTR Sensor pin7
  • Ardumoto Digital pin 10 - QTR Sensor pin8
  • Ardumoto GND - QTR Sensor pin GND
  • Ardumoto 5V - QTR Sensor pin VCC
  • Ardumoto Terminal A 1 - Black wire of Left motor
  • Ardumoto Terminal A 2 - Red wire of Left motor
  • Ardumoto Terminal B 3 - Black wire of Right motor
  • Ardumoto Terminal B 4 - Red wire of Right motor
  • Ardumoto Terminal VIN (+) - Positive/Red wire from battery holder (switched)
  • Ardumoto Terminal VIN (-) - Negative/Black wire from battery holder

Note : Digital Pin 3 is skipped and used by the Ardumoto motor driver. Ardumoto also uses pins 11, 12, and 13.

Important : While the Gobbit should run proper with the connections noted, switching of the red/black motor wires, and/or the A/B side of the Ardumoto may be necessary with the Magician.

Step 5: Arduino Sketch...

If you are new to Arduino, or need some further detail on how to install the software and where to save Sketches, you can find detailed instructions for windows here :

Download the Sketches and Library here :

Extract the zipfile and move the " BasicLineFollower_08232015a" and “MotorDirTest_08232015a” folders to your Arduino sketches folder.

Move the "QTRSensors" folder to the Arduino libraries folder.

Plug in your Arduino/Redboard to your computer with the USB cable.

Open and upload the “MotorDirTest_08232015a” sketch.

Open the Serial Monitor and test your motors for correct wiring. See comments at the top of the sketch to help you make wiring changes if needed.

After the motors are turning correctly, open and upload the " BasicLineFollower_08232015a" sketch.

Step 6: Test and Tune...

Unplug your robot from the USB and set your robot on your lined course and turn it on. You should see the robot turn back and forth over the line and begin following.

You can "tune" some of the variables in the sketch to affect its performance. Until you understand how the sketch works, only adjust the couple of variables noted for "Tune."

The sketch is only a basic example to help you learn several fundamentals of sensing and motor control. The real fun begins as you tune some of the variables and add further refined control functions while developing an understanding of how to instruct the robot to accomplish tasks.

Step 7: Conclusion...

Hopefully, with this tutorial, you have gained some basic understandings of control methods like Proportional control and or PID which can be useful in robotics and automated control systems.

Additional information on programming and tuning with PID can be found in our Instructable :

Programming and basic loop tuning

This is a great project for Boy Scouts looking to earn their Robotics Merit Badge like these Scouts did at Scoutbotics 2016.

Another fun extension of line following is Maze Solving. With the same robot you made here, you can make it run mazes like this Instructable:

Here are a couple short videos of the robots maneuvering under the conditions we suggested previously :



    • Paper Contest 2018

      Paper Contest 2018
    • Pocket-Sized Contest

      Pocket-Sized Contest
    • Science of Cooking

      Science of Cooking

    We have a be nice policy.
    Please be positive and constructive.




    hello ı got 1 problem , what must ı chance for white line follower

    how did you use the qtr-8rc in fritzing?

    im using the following hardwares to build this project.....where am i supposed to make a change??

    1) L293D (in stead of sparkfun motor shield)

    2) arduino UNO

    3) QTR 8RC

    i had to declare the "motor input 1/2 pins and pwm pins" for L293D, and changed code accordingly inside the sketch.

    But i used only 6 from 8RC sensor pins.... The rest of ur code remained the same....

    where else am i supposed to make a change in the code?

    it's noted that, after I uploaded this changed code, the robot only moves on the white spaces and stops as soon as it reaches the black line......but it is supposed to do the opposite :D !

    i'm testing the motors but nothing happens. can't be the wiring 'cause there are 4 wires of the motors. i tried both 9v and 5v power. the shield? i can't understand how to use it.

    can this be scaled up to carry something like 70lbs? I know the motors would all bee much larger, but is the tech essentially the same?

    Yes, this concept could be scaled up to a larger robot.
    The Max series have been used for this purpose:

    Here is Max based project:

    In most cases, you could use the same controller, motor driver and sensor (just check the current and voltage ratings)

    What can be used instead of Sparkfun Ardumoto shield??

    Did you figure it out?

    The first sequence is a calibration. That is the rightleft repeat. After should start following if it is wired correctly and the calibration was successful.

    Are you using the same hardware as the instructable?