A Basic Line Following Robot

Basic Line Solving Robot Project

This tutorial will help you create an Arduino based robot that can follow lines.

Picture of Basic Line following Robot with Arduino
20121204_152841.jpg
gobbit_lf.jpg

 

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

http://en.wikipedia.org/wiki/Proportional_control

PID

http://en.wikipedia.org/wiki/PID_controller

  

Step 1: Build a course...

Picture of 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...

Picture of Robot Build List...
PID.jpg

1. Arduino Uno or Sparkfun RedBoardhttp://www.zagrosrobotics.com/shop/item.aspx?itemid=868

2. Sparkfun Ardumoto shield http://www.zagrosrobotics.com/shop/item.aspx?itemid=782

3. Pololu QTR-8RC Reflectance Sensor Arrayhttp://www.zagrosrobotics.com/shop/item.aspx?itemid=896

4. Robot chassis :

Magician http://www.zagrosrobotics.com/shop/item.aspx?itemid=859

or

Gobbit http://www.zagrosrobotics.com/shop/item.aspx?itemid=958

5. Jumper Wires http://www.zagrosrobotics.com/shop/item.aspx?itemid=834

6. USB cable which matches your choice of Arduino/Redboard

7. AA batteries

Everything to build the robot, except the line sensor, can also be purchased as a discount bundle:

Zagros Robotics Starter Kit - Magician Version (http://www.zagrosrobotics.com/shop/item.aspx?itemid=914)

or

Zagros Robotics Starter Kit - Gobbit Version (http://www.zagrosrobotics.com/shop/item.aspx?itemid=951)

 
 

Step 3: Robot Assembly...

Picture of Robot Assembly...
20121204_152841.jpg

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...

Picture of Wiring...

A detailed wiring diagram can be found here:

http://www.zagrosrobotics.com/files/ZagrosLineMazeFollowWiring_08232015a.pdf

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...

Picture of 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 :

http://www.zagrosrobotics.com/files/ZagrosArduinoInstallation_08232015a.pdf

Download the Sketches and Library here :

http://www.zagrosrobotics.com/files/ZagrosBasicLineFollower_08232015a.zip

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

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:

http://www.instructables.com/id/Robot-Maze-Solver/

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

Instructions for building a simple line following robot.

Copyright 2015 - Zagros Robotics, All Rights Reserved - Please send webpage comments or corrections to webmaster@zagrosrobotics.com - Zagros Robotics,12148 Lackland Road, St. Louis, MO 63146- 7342, (314)341-1836, info@zagrosrobotics.com for answers to any questions.

Zagros Robotics, Inc
ASP.NET Shopping Cart Software