loading

09/07/2015

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

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.

<p>What can be used instead of Sparkfun Ardumoto shield??</p>
<p>Can somebody help me with the programming???</p>
<p>Did you figure it out?</p><p>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.</p><p>Are you using the same hardware as the instructable?</p>
<p>yes, same hardware, same program, same wiring...</p>
What robot are you using?<br><br>Have you confirmed the qtr sensor is orientated correctly with the headers/wires towards the middle of the bot and sensor located at the front of the bot?<br><br>When you say Left left left left, do you mean short corrections to the left or just spinning forever to the left?<br><br>The difference in operation between battery vs. Computer powered, is it a difference in speed only?
<p>hi, it seems like i'm having the same problem. my robot when powered by computer does the calibration sequence then spins constantly to left, when powered my battery it just spins to right in short bursts.</p>
<p>It sounds like a wiring problem. Double check each wire.</p><p>What hardware and robot are you using?</p>
<p>dose the black line width matters???</p>
<p>What works well is black vinyl electrical tape, which is about 3/4&quot; wide. Very narrow may be problematic. Super wide (nearly as wide as the entire sensor array) will probably be more difficult for smooth tracking with the basic code.</p><p>The program is also set for a white background with dark tape. You can change the code if you want the opposite.</p>
<p>If I wanted to change the speed of the robot, where in the code would I do that?</p>
<p>Look in the follow_line() function. There are values of 55 and 200 you will see spread through that function. Try adjusting those or rewrite it to just slow down one wheel while the other runs at full.</p>
<p>Hi, I have made all the mechanical stuff, but am facing difficulty with software. Robot is running weirdly. RIGHT, LEFT, RIGHT, LEFT, LEFT, LEFT, LEFT. Not at all following the line. By the way, robot is running in a different way when connected to computer, and running differently when connected to Battery case for power supply.</p><p>Please help me.</p>
<p>Does your code have the same basic format for if I were doing the same project but on a mbed instead of arduino?</p>
<p>how to make it using the official motor shield and magician chassis.</p>
<p>hi! i want to use Motor Driver 1A Dual TB6612FNG instead of ardumoto sheild , my question is will it work fine with this robot chassis or there will be any compliacations ?? pleaseeeee reply!!!!!</p>
You should be able to use any motor driver you want that will meet the motor requirements (6vdc, 250mA max). The example program will need to be modified to work with your motor driver.
Can i use adafruit motor shield? Insted of adumoto?
<p>Hey, I've got a problem. I did everything as it' s said in the tutorial but the robot is keep moving forward istead of following the line. Can someone help me?</p>
<p>i had connect the arduino n 10A motor shield to power window motor with additional 6v battery, why my speed motor are different between Left and Right</p>
<p>please help me</p>
<p>please help me</p>
<p>I am having trouble with powering the ardumoto. Where does the Vin for the ardumoto go to??</p>
<p>Vin is to power the motors from the L298. It has a max input of I believe 18vdc.</p><p>Here is tutorial on the board. Ignore the part where it says Vin is optional! If you really want you bot to move, it's not. If you are powering the yellow gear motors or micro gear motors, I recommend using at least 5 rechargeable AA or a 6v NiMH or NiCAD battery pack. </p>
<p>Hi I am trying to do your project. I cant add the library to arduino. some people said they had to update the file to arduino.h, no sure what you mean by that. It would be great if you couls help, thax. </p>
<p>Hey! Sometimes it's helpful to scroll through the comments ;)<br>Do you get an error like the one described by SoonK further down? <br>Then this should solve it:<br></p><p>The problem appears, beacuse the code is for an older version of the Arduino program.<br>You <br> have to go into the imported library and open the files &quot;Button.h&quot;, <br>&quot;engine.h&quot; and and &quot;navigation.h&quot; and in each one replace the line <br>#include &quot;WProgram.h&quot;<br>with<br>#if defined(ARDUINO) &amp;&amp; ARDUINO &gt;= 100<br> #include &quot;Arduino.h&quot;<br>#else<br> #include &quot;WProgram.h&quot;<br>#endif<br><br>This <br> will solve the errors above, but a new error will occur saying theres <br>no &quot;wiring.h&quot;. To solve that problem go into the file <br>&quot;PololuQTRSensors.cpp&quot; and replace<br>#include &quot;wiring.h&quot;<br>with<br>#include &quot;wiring_private.h&quot;</p>
<p>Hello,</p><p>I want to know to program a bot when it approaches a t section.for eg. if bot approaches 1st t section then it should go forward and when it approaches 2nd t section it should turn left or right</p>
<p>Hello, </p><p>I am trying to do this project and could quite download the entire code. I am using the exact same parts. I am also using ArduinoUno R3 IDE1.0.6. Every time I try to open the the code it gives me an error that says that the file QTTRC Line follow needs to be inside a sketch folder Qttrc_Line_follow --&gt; how do you do this?</p>
<p>Just make folder named &quot;QTRRC_Line_Follow&quot; and put the file inside... then it will open.</p>
Thanks for your help, finally got the robot working fine. <br>http://www.youtube.com/watch?v=KI_Y90df9Xw check it out! lol
<p>can you give me code?</p>
<p>Hi, Nice project!</p><p>I have replaced all wprogram.h and wiring.h references with arduino.h to bring the sketch up to spec with IDE 1.0.6, it is all verified and OK.</p><p>I am at the stage where I have uploaded the code and the robot seems to not be able to detect my line, it simply keeps driving forward (which i think is no-line detected behaviour). I have the sensor mounted about 3mm from the surface.</p><p>Any help would be greatly appreciated.</p><p>Thanks.</p>
Did you go through the line sensor calibration procedure?
<p>Thanks for the response,</p><p>Yes I did, I found that the corrections it was making were too small to detect when it was travelling as fast as it was. I reigned it back in to a slower speed and saw better results.</p>
<p>Hey u3016798,</p><p>I also have my robot working but not following the line. How did you slow it down? Which program and what exactly did you change? Thanks in advance.</p><p>Richard</p>
<p>Hello,</p><p>when you changed it to arduino.h, is this library included in initial download or do you have to also find the arduino.h library?</p>
<p>i keep getting this error. i have already downloaded the library, and I am using the code that was in the QTRRCExamples folder. </p><p>In file included from QTRRC_Line_Follow.pde:1:</p><p>C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/Button.h:23:22: error: WProgram.h: No such file or directory</p><p>In file included from QTRRC_Line_Follow.pde:1:</p><p>C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/Button.h:34: error: expected `)' before 'buttonPin'</p><p>C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/Button.h:42: error: 'uint8_t' does not name a type</p><p>C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/Button.h:43: error: 'uint8_t' does not name a type</p><p>C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/Button.h:44: error: 'uint8_t' does not name a type</p><p>In file included from QTRRC_Line_Follow.pde:3:</p><p>C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/engine.h: In function 'void engineSetup()':</p><p>C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/engine.h:23: error: 'OUTPUT' was not declared in this scope</p><p>C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/engine.h:23: error: 'pinMode' was not declared in this scope</p><p>C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/engine.h: In function 'void motor(int, int)':</p><p>C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/engine.h:33: error: 'HIGH' was not declared in this scope</p><p>C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/engine.h:41: error: 'LOW' was not declared in this scope</p><p>C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/engine.h:45: error: 'analogWrite' was not declared in this scope</p><p>C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/engine.h:46: error: 'digitalWrite' was not declared in this scope</p><p>In file included from QTRRC_Line_Follow.pde:4:</p><p>C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/navigation.h: In function 'void calibrate(PololuQTRSensorsRC*)':</p><p>C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/navigation.h:21: error: 'delay' was not declared in this scope</p><p>plz help</p>
<p>You probably solved it meanwhile, but I'll answer anyway for anybody who has the same problem (like me):</p><p>The problem appears, beacuse the code is for an older version of the Arduino program.<br>You have to go into the imported library and open the files &quot;Button.h&quot;, &quot;engine.h&quot; and and &quot;navigation.h&quot; and in each one replace the line <br>#include &quot;WProgram.h&quot;<br>with<br>#if defined(ARDUINO) &amp;&amp; ARDUINO &gt;= 100<br> #include &quot;Arduino.h&quot;<br>#else<br> #include &quot;WProgram.h&quot;<br>#endif<br><br>This will solve the errors above, but a new error will occur saying theres no &quot;wiring.h&quot;. To solve that problem go into the file &quot;PololuQTRSensors.cpp&quot; and replace<br>#include &quot;wiring.h&quot;<br>with<br>#include &quot;wiring_private.h&quot;<br><br>That should do it, worked for me!</p>
<p>if i chang th color of line for ex (white line and black background )what is chang in program?</p>
<p>Hello, </p><p>I am trying to do this project and could quite download the entire code. I am using the exact same parts. I am also using ArduinoUno R3 IDE1.0.6. Every time I try to open the the code it gives me an error that says that the file QTTRC Line follow needs to be inside a sketch folder Qttrc_Line_follow --&gt; how do you do this?</p>
<p>for coding of line follower click on:<br>http://ismrobotics.blogspot.in</p>
<p>i want to ask you guys that can I use the same code which is for arduino in freeduino??please reply</p>
We are unfamiliar with the Freeduino, but if it uses the Arduino development environment and has the same I/O it should work.
<p>Even though Button.h is included in the library you provided, it is not included in the sketch. Is there a reason you included it?</p>
<p>tell me the components used in making the line following robot</p>
<p>maja ko</p>
<p>maja ko</p>

About This Instructable