Robot Zero. A Line Follower for Beginners

If you have ever attended a robotic contest and you want to take part in it, or if you are interested in building a line follower this project might be a tower of strength. In this post you will find a detailed description of all the steps taken to end up with a basic line follower, easy to do and low cost, ideal for beginners who always wanted to enter into the fascinating realm of robotics. Although, the project as a whole has already been developed at Robot Zero (in Spanish) I would like to gather the most relevant concepts turning out the final version.

One of the common targets at C.I.r.E. Is the development of line followers, actually we have been discussing this topic for months and a few ideas have come up. Aiming at summarizing these ideas I hereby present my final version of Robot Zero.

I am not an expert on this I have participated in a couple of contests, nevertheless due to the lack of information I hope this document can set a couple of guidelines for those who are willing to compete but not fully knowledgeable of the basic concepts. Having said that I would like to point out that I don’t guarantee the same outcome, I only state what has worked for me, hence the performance will be subjected to the designer’s criteria.

One alternative for beginners is to buy an already built line follower kit, internet offers this choice. I totally discourage this option, since it losses a big part of the appeal, everything is assembled an mostly programmed so the major challenge is virtually reduced to push a bottom. In addition, I presume this sort of robots won’t be allowed, the merit that entails is minimum therefore it is not worthy of been awarded.

The first thing to design a robot is a proper selection of the components and probably this is the first difficulty to be tackled by newbies, questions like what kind of motor or sensors do I need, are likely to come up at this stage. The best option I have found are the Pololu components, with a very reasonable price we can choose everything is needed to meet the performance standards in the competitions, we are not going to win but we might go successfully through the qualifying sessions which would be a great achievement for a novice.

My components selection is as follows:

We can choose between two types of DC motors for this project, if your objective is to build your first line follower and you would be happy with get it to work, then I suggest to select option B. On the contrary if you rather run as fast as you can then go for option A. The issue with the latter is that the motors will request a significantly higher source of current and there is a possibility of burning the DC-DC out, the possibility is remote but it does exist. From my point of view, these are the motors with a superior quality/price ratio. With the chosen wheel and the option B the maximum speeds are around 2 m/s while with A the top would be close to 4 m/s.

Looking at our budget we could have the lot for $122.66, if we add another $10-15 we will have everything we need to crack on. This list includes two different north American suppliers, each shipping expenditure is between $10 and $15 for an economy delivery and it will take up 7-12 days to Spain, you have to consider the fact that depending on where you live you might encounter custom duties.

Nonetheless if you live within Europe and if you cut the shipping costs you can buy all at , the only drawback would be that the change rate is $1 = €1 instead. You can think it through and go for your most affordable choice.

In order to assemble all the components there are two alternatives: we can either use a PCB that works as a chassis too or place a PCB/stripboard onto another base. Below I show a picture:

For our purpose the best decision would be to build a external chassis and attach the electronics on, because it will allow us to have several interchangeable chassis providing flexibility and consequently adaptation to different tracks, this way we can test configurations differing in width and/or length and pick the one which suits best. For instance, if there is track featured by large turning radius and straight stretches it may be convenient to have a longer and wider chassis, whereas if the configuration is mainly composed of small curves and short straight stretches a smaller design is likely to perform better. Besides the robot dimensions are dependent on the inertia and friction forces that reach with traction, therefore the easiest way of assuring the optimal size is to try diverse arrangements out.

If we have put everything together sharing a PCB we can’t easily change its dimensions, this is usually the case if we decide to buy a commercial robot due to economic reasons and ease to manufacture, if you are concerned about the overall weight I should state that the difference can be neglected. The weight of plastic is roughly the same to PCB offering similar stiffness. For all these reasons, I believe that the first design should encourage beginners to learning and testing new ideas so an interchangeable would be desirable.

The final purpose is to have something like this, a robot to attach onto different bases.

Let’s start building the chassis, my suggestion is to design a layout either hand drawn or computer aided. We can stick the template onto a piece of a 3 mm thick Forex or expanded PVC, for boring you can use a drill previously marking the holes with a bradawl (this is an important task since the motors should be perfectly aligned) and with a utility knife we can cut the PVC following the contour. A good point to choose expanded PVC is that it is very use to work with and no sophisticated equipment is needed.

Below I attach a couple of samples (usually to enter competitions your size must be within the maximum dimensions permitted) and a picture of the base manufacturing process.

Base 1.

Base 2.

In my opinions, these aren’t the ideal dimensions but they are the ones I have tested.

What we need to assemble the electronics is to either a PCB design or we can use a stripboard, as Guillermo previously explained here, which might be the easiest solution for those of you who aren’t familiarised with home made PCB techniques. In addition, we can use double sided tape to adhere the selected battery to the electronic board, in a way that its location is in the lower part of the robot. This will cause a lowered centre of gravity.

The image below is a close-up view of the electronic board.

The technical features of the assembled electronics would be:

  • Either 8 digital IR sensor inputs or 6 analogue corresponding to the central ones ( I didn’t want to desolder the ADC potentiometer to use 8 sensors instead).
  • 1 Digital output to enable/disable the IR emitting diodes and hence adjust its light threshold.
  • 2 LEDs.
  • 1 general purpose push button, activation, RC sensor calibration, etc…
  • 2 switches to select different programmed strategies, this is essential to modify the speed against other competitors, if we want to take a risk switching speed to full blast.
  • 1 DC/DC converter which supplies a constant reference voltage to the motor driver, this way the control policy can be simplified.
  • 1 connector to provide a 5V outpout and Serial USART communication, Rx and Tx pins, in case we wish to communicate our robot through a module to the PC.
  • Battery duration: 28 minutes (PWM 160/255, Average speed = 215 cm/s running on the tested track).

In case we are using high-power motors the DC/DC might be burnt out if we don’t add the electrolytic capacitor placed close to the converter board, of if its value is too small. Even though it is the typical component in every dissipative regulator this capacitor supplies the current peak demanded by the motors while their c.e.m.f. Are low.

Particularly, I am using a value of 22 uF and it is enough indeed for the motors to work at high speeds. I tested what would happen if I removed this capacitor and check whether the regulator will cut off for the overrated current demand and it turned out burnt out, as the HP motors can exhibit current peaks up to 1.6 A per motor and the DC/DC only supports up to 2A inputs. By placing this capacitor (locating it closer to the converter or doubling its value) we shouldn’t have this problem with the robot running at fast speeds. With the other motor selection there aren’t any worries since their current consumption won’t exceed 0.36 A rated at 6V.

In order to plug the microcontroller board, as well as the DC/DC regulator, we can employ female 0.1” pitch breakaway connectors. This option is pretty versatile as it allows us a further use of the components for other projects. If we have picked the HP motors the DC/DC voltage regulator would be configured to provide a 5.5-6.5 V output, on the contrary if our design is composed of low power motors the voltage output has to be 9V in order to get more torque and velocity out of them.

The battery connectors, push buttons and so on could be purchased at Pololu too (increasing the possible custom duty), however usually you will have a local supplier where this kind of products are easy to find at a reasonable price.

The electronic schematic (click the picture for more detail) will result in something like that, unless I have mistaken any pin assignment (it has been reviewed so shouldn’t be the case).

C1 and C2 are the 22uF electrolytic capacitors, R1 R2 and R4 equal to 470 Ohms, R10 R7 and R8 330 Ohms, R3 R5 and R6 15K, a dissipative 5V voltage regulator, if we are draining from the DC/DC 9V then we could select a 7805, but while draining only 6V it would be better to pick one with a lower drop-out voltage such as LF50ABP, L4941BW, namely any LDO. The SMD components are 1206 size.

A picture showing the mounted electronic components and the layout.

Let’s attach the electronic board, once soldered, to the base of the robot. In order to connect the motors you can either employ a couple of matching connectors or solder the wires directly to the board. The next step is to stick the battery to the PCB with double sided tape.

We can screw or glue the ball caster, the latter action will imply a caster per chassis. Finally we can screw the sensor board, having drilled the necessary holes before, and tailor the ribbon cable to connect them to the main board.

Concerning the sensor board we have to replace both resistors or remove one of them, since the sensors are going to be placed too close to the floor and the original values are intended for for the value which the resistors are intended for a larger distance.

In the image above you can tell how two resistors have been replaced by a 50 -100 Ohm one, the formers were associated in parallel and were limiting the current drawn by the IR diodes, we can either one or both and solder another back (as shown in the image). Though I haven’t tried a long range of different values, a 82 Ohm resistor should do the job. This will vary as some of the boards will come with 43 Ohm resistors and other with 66 Ohm. Another fact that has been checked is that unfortunately these boards don’t provide good analogue readings, because its inclination strongly affects the readings, the track surface is not perfectly flat therefore the robot will be subject to certain vibrations or oscillations, we might encounter some trouble with the readings. This effect will show up when the telemetry techniques are developed at C.I.r.E., I guess that would be next stage.

The outcome should be something like this:

Everything said so far had to do with a physical construction of the line follower. The remaining part will rely on programming. I attach a simple code example which controls the robot at a constant speed following a line virtually with no oscillation. The amount of time devoted to the software hasn’t been large, it is the first programmed and has been running on different robots as its performance seemed to be adequate, having said that you may find any bugs. The overall approach is very straightforward and consists of measuring the distance from the centre of the line, calculate the speed which the line is getting closer or farther away from the centre, multiply these measurements by the constants that tune the robot response, add them all and convert the result into an offset in both motor speeds which generates a rotational movement in combination to the translational displacement.


I have uploaded a couple of videos where the final performance is exhibited, the second one was captured at high-speed (from second 30). The robot is assembled with the longest base and the DC/DC output voltage is 6.4 V.

High-speed video capture (from second 30).

The average speed showed is 210 cm/s. I think in the last Spanish national contest the winner achieved an average velocity of 260 cm/s, although is not totally comparable as the resulting speeds will rely on the type of track. Nevertheless, I believe with this performance one should go through the qualifying sessions and at least get to the two robot stage. We are not going to win with this design, but it wouldn’t be fair to compare a robot whose whole cost could be equivalent to the price of some of a single rival’s motor either. In addition, the top competitors are regulars in these sort of disciplines and their robots have been largely tested.

This is my suggestion for a line follower robot whose intention is to gain an insight into the basic concepts: hardware, components selection and simple programming to track a line, if you require further explanation you could find it here (written in Spanish).

There is still a great deal of work to do on the software development, which could be where a considerable part of the difficulty lies and necessary to carry out if you want to get quicker and more competitive. The set of ideas and strategies is extensive, however my intention is not to enter any competition and so I am not going to work on those, in the current situation it isn’t worth and there are other projects which will demand time and are targeted at C.I.r.E.

For those of you who are entering this hobby I would like to recommend you to share your improvements, it is the only way to learn and provide access to potential hobbyists as well as spreading the competitions. In Spain the fact of being competitive won’t pay off in the current situation, there aren’t enough hobbyists and there is no point in winning a contest which people have forgotten about in a couple of months. Anyway, it may come a day when we will have an actual Robotics community but I am afraid we won’t get it while the main ambition is to collect newspaper cut outs.

I hope the attempt at explaining the construction of a line follower robot will be helpful to someone, that will justify the effort invested during prototype design and testing a few versions…

Visitas :190726
Both comments and pings are currently closed.

76 Responses to “Robot Zero. A Line Follower for Beginners”

  1. mustafatasci42 says:

    hi i m mustafa. i making ur robot zero project. but dont working true. because m2forward everytime full speed. m1_forward normally. thnx for everything

    • JM says:

      Hi, this code works: (compiler optimizations must be enabled)

      • mustafatasci42 says:

        thnx. i found error. i sellected unsigned char in compiler options. because errorp dont coming negative.
        i ve a new problem. i wanna add one analog sharp this robot. can u help me.
        robot line following. if find front closed door motors stop vait after opened door continous. (sory my english)

        • JM says:

          Hello, if you are using our schematic you can find a connector in the baby orangutan (ADC6) to connect the sensor.

          Vcc and GND for the sensor can be found in the 4 pin connector.

          All you have to do is read the sensor and change the speed value based on its reading.

          If you are using AVR check the forums to find information and help with technical issues

    • Raúl says:

      Hi, Thanks for your interest. With the information you have provided it sounds as if you have some trouble with your electronic connections. Have you checked if you are getting good signal from your sensor readings? Could you elaborate on your problem?

    • adem06 says:

      Hi, I am writing from Turkey I want to ask something on the black and white, this program was written for the robo zeronun how this program can convert them to black-on-white, Waiting for your help
      DinleyinFonetik olarak okuyun

      • JM says:

        Hello, if the robot has to follow a white line on a black surface you can use the == operator instead of != to read the sensors.

        Change the next lines:

        in the function obtener_errorp(void):

        if(((PINC & 0×04) == 0) && ((PINC & 0×08) == 0))

        if((PIND & 0×10) == 0) //I3 PD4 -7
        errorp = errorp – 0×07;

        if((PINC & 0×01) == 0) //I2 PC0 -5
        errorp = errorp – 0×05;

        if((PINC & 0×02) == 0) //I1 PC1 -3
        errorp = errorp – 0×03;

        if((PINC & 0×04) == 0) //I0 PC2 -1
        errorp = errorp – 0×01;

        if((PINC & 0×08) == 0) //D0 PC3 +1
        errorp = errorp + 0×01;

        if((PINC & 0×10) == 0) //D1 PC4 +3
        errorp = errorp + 0×03;

        if((PINC & 0×20) == 0) //D2 PC5 +5
        errorp = errorp + 0×05;

        if((PIND & 0×80) == 0) //D3 PD7 +7
        errorp = errorp + 0×07;

        in the function Obtener _errord(void):

        if(((PINC & 0×04) == 0) && ((PINC & 0×08) == 0))

        else if((PINC & 0×08) == 0) //D0 PC3 +1
        error = 1;

        else if((PINC & 0×04) == 0) //I0 PC2 -1
        error = -1;

        else if((PINC & 0×10) == 0) //D1 PC4 +3
        error = 3;

        else if((PINC & 0×02) == 0) //I1 PC1 -3
        error = -3;

        else if((PINC & 0×20) == 0) //D2 PC5 +5
        error = 5;

        else if((PINC & 0×01) == 0) //I2 PC0 -5
        error = -5;

        else if((PIND & 0×80) == 0) //D3 PD7 +7
        error = 7;

        else if((PIND & 0×10) == 0) //I3 PD4 -7
        error = -7;

  2. erdal says:

    hi,this is excellent project.thanx.
    I have some problems with baby orangutan.
    I not found it in Turkey.
    I want use atmega168 and tb6612 building a ” baby orangutan”
    what is your idea?good working

  3. erdal says:

    hi,jm thanks. what is trimpot mission on baby orangutan?
    what is it’s value?

    • JM says:

      Hi, the potentiometer is connected to the ADC. We don’t use it in our robot. You can remove it if you want.

  4. erdal says:

    thanx jm, and this is last question:)
    how use sws002 switch programming or working baby orangutan?(programming on/off)

  5. erdal says:

    hi jm, please say, how to programming avr studio with baby orangutan? I use (Pololu USB AVR Programmer). all settings ok. but avr studio is connection failed to usb avr programmer.can you help me, please

  6. erdal says:

    thank you jm,

    i success programming.avr usb programmer firmware updated to 1.04 ver.

    what is th freq. of this motor driver tb6612?our motor

    driver exploded:( we want use L298 what do you think

    • JM says:

      Hello, the PWM frequency is 9.8 KHz.

      L298 is a good choice, it is a bjt bridge so its voltage drop (1.5-1.8 V) is bigger than in mosfet bridges (< 0.5V). Take this into account when you select the motor voltage (6 V + 1.5 V).

      • Adzlan says:

        also, if im using the pololu 5:1 Micro Metal Gearmotor, 2500RPM 0.36A stall, will the performance varies a lot compared to the 10:1 3000RPM 1.6A stall? because i dont want to risk of burning the driver.

  7. erdal says:

    hi jm thank you for assistance.
    please tell me, how do you do avr studio compiler options?

  8. erdal says:

    hi jm, thanks.
    i have a problem.
    our line color is “white”. other place color is black.

    what to change code? thanks.

    • JM says:


      I don’t have any programme done for that case, you will need to think and adapt the programme to read the line in both situations :)

  9. lamis says:


    this line follower is very good in my opinion , but i want to ask you some questions about sensors why did you use 8 ir sensors what is the different if i use only 4??

    • JM says:

      Hello, thx,

      the robot uses 8 sensors because Pololu sells this sensor board.

      The bigger the number of sensors, bigger is the proportional error that can be measured, and bigger is the space where we can measure the derivative of the error.

      As disadvantage the bigger number of sensors, bigger weight in the front of the robot.

      It is difficult to find the suitable number of sensors and to estimate the maximum error measure that is going to be required, this is out of the scope of this robot which tries to be a robot for beginners.

  10. robo11 says:

    hi can i code this with arduino platform am actually planning to make a lfr
    from your tutorial.
    i know interfacing with arduino

    • JM says:


      yes, you can use an arduino with ATmega328p, Baby Orangutan is compatible with Arduino.

      • ashwinj92 says:

        hello jm,
        i would like to applaud whole heartedly for your effort to make this tutorial its very informative,for beginers i have 2 doubts to be cleared i have made a couple of line followers but want to try this i dont know making pcb design ….although i did most of the projects on my arduino uno, so my questions are
        1.) are you using 10:1 HP micrometal gear motors or just normal 10:1 micrometal gear motors because i have a doubt on the stall torque compatibility of HP micrometal gear motors with baby o 328s motor driver the stall current for pololu made HP motors are 1600ma but the baby orangutan 328 supplies only a max current of about 1AMP per channel if you use 2 of these motors then motor driver would draw a current of 3200ma when both the HP motors are stalled
        so does this damage the motor driver on baby o328 due to execess of heat
        please suggest me the precautions to be taken so that the motor doesnt stall.
        2. are u using qtr 8a sensors in this project and how many of these have you used
        3.please tell me how many digital pins are available to the user other than that of four digital pins used for motors ,the digital pins which inturn are not used in any other circuitry connections in baby o 328p
        only available freely to the user so using them doesnt affect any other process on baby o 328p

        4.does the arduino functions work on 328p with 20mhz or 16mhz i know arduino functions are mostly 16mhz.

        thanks for the help jm,

  11. jamieexp22 says:

    my question is also the same as above…
    can the orangutan b 328s motor driver handle 3200ma of current

  12. Raul says:

    Hi guys and thanks for your interest,

    The following reply is on behalf of JM, who due to technical difficulties it seems a bit of a hassle to get connection.

    1. You can use either type of DC motor, in case of the 10:1 HP one you will get a higher performance, but at the risk of burning the dc-dc out unless you attach a capacitor across its output, the H-bridge on the baby orangutan could also be damaged in case the motors stall. We have successfully tested the 10:1 hp controlled with the baby orangutan with good results, as long as the motors don’t stall everything should be fine, if they do the driver will burn out.

    2. Sensor wise, we use 8 IR sensors in the analog board, they are treated as digital though wreading either 1 or 0.

    3. There are 15 pins available, a few of which are exclusively assign for ISP programming purposes, this is a fact to bear in mind when choosing what to connect to those pins.

    4. We don’t use the arduino development environment, instead we went for the avr-gcc compiler adding the atmel environment, hence I don’t know what to suggest.


  13. jamieexp22 says:

    thanxs for the reply raul,

    so doesnt the motor driver last even for 1 second if the robot stalls.what i meant to say is stalling the robot for one second is enough to damage the baby o 328s h bridge
    or stalling for a prolonged period(5 to 10 seconds) will damage the h bridge.

    i actually ordered baby o 328p and hp motors from pololu which will be shipped in a couple of days to me.

  14. jamieexp22 says:

    thanxs for the reply raul,

    so doesnt the motor driver last even for 1 second if the robot stalls.what i meant to say is stalling the robot for one second is enough to damage the baby o 328s h bridge
    or stalling for a prolonged period(5 to 10 seconds) will damage the h bridge. because there might be instances where the robot could run it a wall so it would stall untill i pick up the robot and switch it off which would atleast take some time interval say 4 to 8 seconds….

    i actually ordered baby o 328p and hp motors from pololu which will be shipped in a couple of days to me.

  15. Raul says:

    No problem,

    I would say you have a few seconds before unrecoverable failure (guys correct me if I am wrong, it might be a fraction of a second), but to be honest I would rather not push its very end boundaries and usually work within a safe margin.


  16. jamieexp22 says:

    i should be extremely careful so that the robot doesnt stall for even a fraction of a second which means i have have to not hold the motors tightly
    i have to add as less weight as possible over the robot, and pwm duty cycles must never reach 100% should keep it at a stable 60% or 70% ..

    i have ordered for 50:1 HP motors which give a stall torque of about 20 oz-in at 6volts. i will be using 2 of these in my project so what range of weight do u suggest to put on the motor so that it there is minimum risk of stalling atleast when the robot is on the track,i will take care of unnatural possibilities like hitting a wall or catching the wheel tightly , if i have 40oz-in max from 2 motors before they stall so please tell me a rough figure i will try to design my bot for that range.

  17. venulokesh says:

    hi can any one explain i am a biginner so iam totally confused with the circuit can u explain

  18. miguel says:

    hola me gustaria que me ayudaras con mi programa es que estoy programando en pic c y mi microcontrolador es un pic18f4550 porfas si me puedes ayudar

  19. […] #gallery-1 { margin: auto; } #gallery-1 .gallery-item { float: left; margin-top: 10px; text-align: center; width: 25%; } #gallery-1 img { border: 2px solid #cfcfcf; } #gallery-1 .gallery-caption { margin-left: 0; } […]

  20. OreHero says:

    Hi. can 1 build the robot zero with orangutan sv-238 and how can i fix the port and sensor

  21. JM says:

    I am sorry, I don’t know the orangutan sv-328 board. If you have any doubt about the board you can ask any question here:

  22. antoni says:

    Hi JM, what’s your email ?, I wanted to send a circuit to take a doubt

  23. antoni says:

    like turning the car via remote control? and also need to record the speed and time spent on the course? … I’m using PIC16F877A with infra red sensors with PWM control (set to 248) … thanks for the help, my email is … I can send the code in c

  24. robomaster says:

    There are some errors in the code that given by you
    For example:
    1. The limes marked as A and B must have different If conditional
    but have same operator “>”

    //Cálculo de la velocidad media del error.
    if (error == error_old)
    tic = tic + 1;
    if(tic > 30000)
    tic = 30000;
    A> if(tic > tic_old)
    errord = errord_old/tic;
    B> if(tic > tic_old)
    errord = (errord_old*tic_old)/tic;

    2.While optaining the error for proportional you are calculating the

  25. robomaster says:

    2. While optaining the error for proportional you are calculating the
    avarage error between sensors.
    But for derivative you dont do the same. It works but It is better to consider this…

  26. Jorge says:

    Hi, thanks for the comment

    1. The code is commented “//” as you can see, A works better than B.

    if (error == error_old)
    tic = tic + 1;
    if(tic > 30000)
    tic = 30000;
    if(tic > tic_old)
    errord = errord_old/tic;
    // if(tic > tic_old)
    // errord = (errord_old*tic_old)/tic;


    2. I prefer to do it in this way, you don’t need to know the error average.


    • robomaster says:

      Hello Again

      Thanks Jorge for your reply.
      Let me discuss about these:
      1. If we named the distance between the wheels as A
      The length of the robot B (from the front wheel to the centre on the
      rear wheels 90 degree)
      Do you thinkis there a best ratio among A and B?

      2. Do you think placement of sensor as closer as possibe
      provides better error sensing?

      3. As I asked before , Why do you think that for derivative correction, avarage value is not necessary? If it is used, doesnt provides us better

      4. instead of counting “tic”s and 1ms interrupts, Doesn’t a forever loop gives us faster and much more calculation at run time?
      efficent and fas

      • Jorge says:


        This is a robot for beginners, and such it is aimed at participating in a robot contest, not to win it. Therefore, many of the topics you arise haven’t been tackled throughout the development of this project, the main area of work has been how to get an easy base with off the shelf components to encourage those who are initiating in this hobby. The software has not received all the time that it would require.

        1. Unfortunately, there isn’t a magic number to reply this, the length and width depend upon a myriad of robot parameters. For instance, the maximum friction exerted by the wheels, weight and inertia distribution, height, motors,… In order to know what the optimal dimensions are, it is fully necessary to carry out an exhaustive mechanical analysis, this would be a whole problem that will require very specific knowledge, could be overwhelming and off putting for those who are beginning.

        What we have done is, instead of focusing on the previous, the effort went into making a robot that one can easily swap the base, and test different longitudes as desired. This requires much less study and time than a complex theoretical analysis of the mechanics.

        2. Agreed, the closer the sensors are the better, you gain higher resolution for the proportional error, even if you choose to get analog reading through the microcontroller ADC. You will increase an awful lot the resolution instead of working with ones or zeros.

        What you need to estimate is what is the area where you would like to detect the error, and how close off the floor you need to place the sensors. On the other hand, the more number you have the more resources you will need from the microcontroller and so the power consumption as well as weight contribution at the front (one of the key factors to avoid).

        3. You cannot calculate the derivative with the average value in this case, since to do so you will need to read several sensors which could cause trouble.

        For example, draw a board with a few sensors and make distance among them much greater than the physical width of the same. Then, draw a line width such it covers just the distance for two sensors, if you move the line at a constant speed underneath the sensor board you will see that most of the time the line activates a single sensor, and in a short time interval the line activates two of them which incurs in a derivative calculation error.

        To tackle this, instead of the average error you just need to read a sensors at a time and count how long it take the line to change from one to another. Doing it like this, you get rid of an error caused by the line width and coupled to the physical dimension and distance between sensors.

        If you think it through you will know what I am talking about.

        The software running on the robot is a straightforward approach developed in 3 or 4 hours, it hasn’t been altered, hence it is bound to be highly improvable. It is just a simple code for those guys who are starting.

        4. You can use a loop instead of an interrupt, the only thing to bear in mind is that the execution time in each iteration is homogeneous.

        In order to work out the derivative value you need a constant sampling time, the reason is that this time is inherit to the controller derivative constant. The easiest way of achieving this is by using an interrupt.

        The shorter the time is taken within the interrupt the better, likewise the derivative term will get a higher magnitude, and you have to make sure that in between tics the microcontroller has enough time to go through the whole code.

        All in all, this is a robot for beginners, the questions that you bring up are for more advanced robots and are beyond the scope of this project.


  27. robomaster says:

    You re right and I was a pleasure for talking to you.
    I am on a development of a line follower. I share my results
    later with you…
    I would like to disguss some other issues, but not suitable for beginning.
    Great effort…

  28. Jorge says:

    Thanks, likewise. Good luck with that robot.


  29. pavan says:

    hi, may i know clearly what is sl5 in the circuit

    • Jorge says:

      “connector to provide a 5V outpout and Serial USART communication, Rx and Tx pins, in case we wish to communicate our robot through a module to the PC.”

  30. Johnny says:

    Hi, I’m brand new, decided to build a robot. Just bought the line sensor Pololu QTR-8RC. Author of the project participants or please help me deal with it, I would really like to work with him. You can ask to help him connect to the MC, not as a robot for the line, but just to see if it works and how to use it, you can give the program or to help write it in WinAVR, for example, that brought the sensor to the black line and the LED lights up . I am new to programming, but you have already, as I see professionals.
    Thank you very much!

  31. Johnny says:

    Sorry, I’m new. I can not compile the code. I would just check the sensor on the LED line. Help please.

  32. Johnny says:

    Sorry for disturbing.
    The last question, my sensor lines Pololu QTR-8RC (digital) will come to your PD robot? I just have a digital and analog sensor you … What to do?

  33. Jhonny says:

    Hi all! Parse your code is not as difficult as I thought! on the basis of his written the software for a digital sensor line pololu. But it does not work, the fact that I do everything like you to a tee! Tell me where the error? I am using ATmega16 16Mhz.
    #define F_CPU 16000000UL
    #define LED_ON PORTD4
    void ports (void);
    int main (void)

    return 0;

    void ports (void) {
    DDRC=0x00; //line sensor mounted on port C
    PORTC=0x00;//line sensor mounted on port C
    DDRD=0xff;//LEDON Port
    DDRB=0xff;//Led port
    PORTB=0xff;//Led port


    int op (void) {
    if((PINC&0x20)!=0) {PORTB=0x00;} // if portc5!=0 then led off!

  34. Jhonny says:

    #include avr/io.h
    #include util/delay.h
    #include avr/interrupt.h

    • Jorge says:


      you can’t use our programme to read the RC sensor, it is for the analog board. To read the RC board you have to charge and discharge the capacitor.

      You can find examples of code in the links above. If you have any question about Pololu’s libraries you can ask in Pololu’s forum, and people who did them and sell the boards will answer you.

      We use the analog board in this robot, not the digital one, so please, use the pololu’s forum to solve doubts about the rc board.


    • Oscar says:

      If you want read the qtr-8rc you should use the pololu library to do that. You can read (though in Spanish the code is easy to understand). The robot in that article is similar to this one.

  35. Jhonny says:

    But unfortunately the code is not working, why?

  36. Jhonny says:

    I am your code from beginning to end, looked and found no case have been posted yet ADC ADMUX and ADSSRA. strangely

    • Jorge says:

      We use the analog board to read the sensor, “1” (5V) or “0” (0V) (we are not using the adc). You can’t do this with the RC board because you have to charge and discharge the capacitor (you can’t read directly the sensor/pin value with the RC board).

      All this is explained in the previous links.

      Check out them, please.

  37. Jhonny says:

    Tell me please, and to motor drivers from Toshiba which vstrivayut in output controllers pololu STBY for what? And I can not find a normal response to datasheet there is only written: STBY I “L” = standby / 200 kΩ pull-down at internal

  38. NeWil says:


    I’m researching on Robot line tracer. Could I please ask if you’
    d programmed ADC interrupt timer?


  39. […] an analog reading of reflected IR by measuring the discharge time of the capacitor. Check out this tutorialfor an example of […]

  40. Rahul says:

    Great job.
    but I just want to know whether it will be able to follow a line of width 3cm smoothly. Actually the middle two sensors are perfectly on line(3cm thick) and the sensors(of both the sides) next to the middle ones remain partially on the line. will it affect the performance even if my code is correct & accurate. please let me know…

    • JMN says:

      Hi, thx for the comment.

      I think that it should work. When the central sensors are over the black line, derivative and proportional errors are zero.

      if(((PINC & 0x04) != 0) && ((PINC & 0x08) != 0)) //R0 and L0

  41. Adzlan says:


    Im new in robots. Do you have other version of this robot using other than babyorangutan? maybe pic? because im having trouble to find the babyorangutan here in malaysia

    • JMN says:

      Hello AdzIan,

      I don’t have any robot which uses pic microcontrollers.

      Regarding the motors, we have not tried out the 5:1 motor, I can’t know if you are going to get good results with this motor, 5:1 motor’s torque may be small for this robot.

      Using 10:1 motors (0.36 A), the robot can reach average speed around 1.6 m/s.

      • Adzlan says:

        hello JMN
        Thanks for your answer! Can this robot make a 90 degree sharp turn? and also tracking a line width of 5cm? Or do i need to modify the coding?

        • JMN says:

          Hi AdzIan,

          this robot can not make a 90 degree sharp turn, the robot must be shorter like the Pololu’s 3PI robot.

          You will probably need to modify a little bit the programme so that the robot can follow a 5 cm line.

  42. […] Robot Zero: a fast line follower for beginners A guide to building a fast (> 2 m/s) line-following robot from scratch. By C.I.r.E., February 2011. […]

  43. […] Detalii: Robot Zero. A Line Follower for Begginers. […]

Subscribe to RSS Feed Follow me on Twitter!