Picture of Basic Line following Robot with Arduino
In this tutorial we are going to go over building a arduino line following robot using Proportional control as the control method. Similar to PID but simpler. I reccommend checking out the Wiki on both control systems.

Proprotional Control


Remove these adsRemove these ads by Signing Up

Step 1: Build list...

Picture of Build list...

1.   Arduino Uno or compatible                                                           

2.  Sparkfun Ardumotoshield                                          

3.  Pololu QTR-8RC Reflectance Sensor Array         

4. Robot chassis                                                                

5.  Jumper Wires                                                                

verything to build the robot except the line sensor can also be purchased as a discount bundle:
Zagros Robotics Beginning Robot Bundle (

Step 2: Assembly...

Picture of Assembly...
After assembling the chassis secure the battery, Arduino and Ardumoto shield to the chassis ( I used zip ties). Next secure the QTR sensor so that it is just slightly above the surface that the robot is going to be moving on. I 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 when tuning your completed robot. Also take notice of the position of the sensor, header pins towards the inside so that the sensor pins match the Arduino sketch.
AnindyaB9 hours ago

i want to ask you guys that can I use the same code which is for arduino in freeduino??please reply

nkarlson5 days ago

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?

u30167981 month ago

Hi, Nice project!

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.

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.

Any help would be greatly appreciated.



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?

ZRob314 (author)  u30167981 month ago
Did you go through the line sensor calibration procedure?

Thanks for the response,

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.

bass.shuru7 days ago

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

ZRob314 (author)  bass.shuru5 days ago
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.

tell me the components used in making the line following robot

Tilokc1 month ago

maja ko

Tilokc1 month ago

maja ko

Tilokc1 month ago

maja ko

SoonK2 months ago

i keep getting this error. i have already downloaded the library, and I am using the code that was in the QTRRCExamples folder.

In file included from QTRRC_Line_Follow.pde:1:

C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/Button.h:23:22: error: WProgram.h: No such file or directory

In file included from QTRRC_Line_Follow.pde:1:

C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/Button.h:34: error: expected `)' before 'buttonPin'

C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/Button.h:42: error: 'uint8_t' does not name a type

C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/Button.h:43: error: 'uint8_t' does not name a type

C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/Button.h:44: error: 'uint8_t' does not name a type

In file included from QTRRC_Line_Follow.pde:3:

C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/engine.h: In function 'void engineSetup()':

C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/engine.h:23: error: 'OUTPUT' was not declared in this scope

C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/engine.h:23: error: 'pinMode' was not declared in this scope

C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/engine.h: In function 'void motor(int, int)':

C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/engine.h:33: error: 'HIGH' was not declared in this scope

C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/engine.h:41: error: 'LOW' was not declared in this scope

C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/engine.h:45: error: 'analogWrite' was not declared in this scope

C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/engine.h:46: error: 'digitalWrite' was not declared in this scope

In file included from QTRRC_Line_Follow.pde:4:

C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/navigation.h: In function 'void calibrate(PololuQTRSensorsRC*)':

C:\Users\Student\Documents\Arduino\libraries\PololuQTRSensors/navigation.h:21: error: 'delay' was not declared in this scope

plz help

nkarlson3 months ago


I have assembled the robot above and uploaded the files into my library on arduino. However the code is giving me problems asking about a WProgram.h. Do you think it is because I have a Mac?

SuryaS4 months ago

Hi What will happen if i use white tape on a black board??
will it still work? What part of my code must i change?

gadriuno8 months ago

In connecting the ardumoto pins to the sensor array, did you have to solder the wires?

ZRob314 (author)  gadriuno6 months ago

We just solder the headers on the sensor then use male to female jumper wires between the sensor array and the breadboard

bitblab7 months ago

I did everything in this tutorial. I also Had to update some of the files to arduino.h to make up for the updated IDE. I know little of arduino programing and programming in general. When I plug in the power the wheels don't move. I don't get it. Does anyone have a sketch for this that works I can get?

gadriuno8 months ago

In connecting the ardumoto pins to the sensor array, did you have to solder the wires?

elliot42068 months ago
How much was the total cost?
calmeida311 months ago
Hi, what do I need to change if I use a QTR-8A (analog) with a arduino uno and na arduino motor shield.
My problem is the basic programm (provided by Arduino) only recognised 4 sensor pin. Any help woulg be appreciated.
Regards in advanced
ppraça1 year ago
hi, can you help me with a very simple question. Where goes connect the 2 wires (red/white and black) attached to the ardumotor. plz answer my question or somebody else.

ZRob314 (author)  ppraça1 year ago
The red/white and black wires on my robot are not used in this tutorial. Those wires are to add more power to the motor drive if needed. I am already powering the arduino through the barrel jack which has enough power to run the arduino and the motors. Please refer to the schematic or look at this other tutorial that has a detailed drawing if your still confused about wiring the robot. -Atom

osas2011 year ago
Thanks for your help, finally got the robot working fine. check it out! lol
osas2011 year ago
Hi, I was playing with the position of the sensors, sometimes it works and follow the black line other times it doesn't. How do i go back in the code and change how far the sensor can pick up the black line? please help.
rgümüş1 year ago
Hi I cant' make my line following robot move. please help me to make it move. I would like to use 8 qtr sensors and motor driver. I couldn't make your codes work
ZRob314 (author)  rgümüş1 year ago
Do you have a specific problem or question about the setup?
osas2011 year ago
Hi, i finally got the code working, had to download all the libraries and put them in the arduino but now the robot is still not working. My prof said becuz i need an extra power supply to power the ardumoto and motors differently because the 6V battery is not enough. Do you think that might be the problem the motors did not move?? Pleaseee help!!
ZRob314 (author)  osas2011 year ago
Have you tried fresh batteries (they don't last very long under use)? Have you tried running the motors manually at full speed?

You can use the motor control example on our website to confirm your robot motors are not binding and everything else is working before attempting the line following:

could you explain how does the code work for this robot. because im building the project for my class
Hi, I came accorss your post when I was doing research on arduino codes. I have the exact set up you have but I don't have any idea how to write a code. I'm useing the Arduino Uno R3, Ardumoto Motor Shield and the QTR-8 Sensor Array. Is there only one code you need to use, a code for each component or what. I'm really not sure what to do. What code will make the robot follow a black line of tape smoothly and quickly? What do I need to do to get the code into the robot?

ZRob314 (author) 1 year ago
With the Arduino look at the BlueSmirf of BlueMate

These are pretty easy to connect up and get going. XBee is also a good and even easier option:
osas2011 year ago
Thanks, I can see you use a Pololu QTR-8RC Reflectance Sensor, for my project i am required to have at least 1 sensor and a 1 communication method. Like Bluetooth, Xbee, WIFI or wired communication. Just wondering with type of communication did you use in the robot? And if i were to try to implement any kind of communication would it change the program(sketch) needed or would it still remain the same. I'm sorry if my question doesn't seem clear. I'm so new to this :(
ZRob314 (author) 1 year ago
It should load fine in version 1.0 - the issue is probably the change in the file extentions. All of the files need to be placed in a folder with the same name as the sketch you are trying to load and run. Let us know if you have any other questions. The older sketches have an extention .pde.
osas2011 year ago
Hi!! I am very much like this robot here!! it's simple and looks beautiful. I am placing orders on the parts now, because i would love to build this, its a school project. I just got some question i and i hope you can help me out. what is the code you use for the Arduino to program it? and when you say the file doesn't work for the Arduino Ide 1.0 and above ## what exactly do you mean? do it mean i have to download an arduino program that is lower? I'm sorry i am just really new to this and i would greatly appreciate if you can guide me through the way please.