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 :
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
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 (http://www.zagrosrobotics.com/shop/item.aspx?itemid=983)
Zagros Robotics Starter Kit - Gobbit Version (http://www.zagrosrobotics.com/shop/item.aspx?itemid=951)
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 :
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 :