Make a Line Follower Robot in 10 Minutes

 

Easy Line Follower DIY Hacking Raspberry pi webcam robot DIY Hacking

Easy Line Follower Robot

Line followers are one of the most prominent kinds of robot. They have existed for a very long time , however the technologies used for building them have changed rapidly. Earlier controller boards the size of bricks were used , but now they have shrunk and become tremendously powerful. Now , technology allows you to build a line follower in just under 10 minutes if you have all the parts for it. So enjoy building this quick and easy line follower. Have fun with this DIY hacking tutorial!

What are the stuff required to do this project?

Hardware :

  1. Arduino / Arduino Clone or make your own custom arduino board with this tutorial.
  2. Two continuous rotation servo motors like this : Continuous rotation servo.
  3. A ball caster : Ball caster.
  4. An infrared sensor array like this : Pololu QTR-8A IR sensor array OR a set of six IR Leds and Detectors.
  5. Resistors : 1K and 10K.
  6. Two robot wheels like this, select wheels after checking if they fit in the servo : Robot wheels.
  7. Chassis , usually a small acrylic board will do.
  8. Four AA duracell batteries and battery holder.

Software :

  1. Arduino IDE : Arduino.

So how does it work?

The working of a line follower robot is pretty straight forward. These robots have the capability to detect a black/dark line on a lighter surface depending on the contrast. They estimate whether the line underneath them is shifting towards their left/right as they move over them. Based on that estimation they give respective signals to the motors to turn left/right so as to maintain a steady center with respect to the line.

These robots usually use an array of IR (Infrared) sensors in order to calculate the reflectance of the surface beneath them. The basic criteria being that : The black line will have a lesser reflectance value (black absorbs light) than the lighter surface around it. This low value of reflectance is the parameter used to detect the position of the line by the robot. The higher value of reflectance will be the surface around the line. So in this linear array of IR sensors, if the leftmost/rightmost IR sensor presents the low value for reflectance , then the black line is towards the left/right of the robot correspondingly.The controller then compensates for this by signalling the motor to go in the opposite direction of the line.

Easy Line Follower

Line Follower Block Diagram

The IR sensor array consists of individual IR LEDs and IR photodiodes. The IR light emitted by the LED strikes the surface and is reflected back to the IR photodiode. The photodiode then gives an output voltage proportional to the reflectance of the surface (high value for light surface and low for black/dark surface).

Easy Line Follower

IR Sensor Working

Step 1 (Optional) : Making the sensor array for the line follower (only if you don’t want to buy the pololu reflectance sensor)

In order to make an IR sensor array , take the six IR LEDs and connect them in parallel with each other. Now, take the IR photodiodes and place each of them just below the six IR LEDs. Wrap each pair together using black insulation tape leaving their tips exposed. Take these six pairs of IR LEDs and photodiodes and join them in a straight line, each pair should be 1.5cm apart from the next.

Easy Line Follower DIY Hacking

IR Photodiode and IR LED


Taping them together

Step 2 : Assembling the components for the line follower

Take the piece of acrylic board and stick the servo motors to the left and right edges using hotglue/super glue. Then attach the ball caster on the opposite edge . Take the pololu IR sensor array or your own sensor array and stick it on top of the two servo motors using a small plastic / foam piece. The sensor must be positioned in such a way that it’s about 4-5mm from the ground for optimal performance.On the top side, stick the arduino board using double side tape, do the same for the battery holder. This is how it looks like :

Easy line follower

Bottom View


Easy Line Follower DIY Hacking

Full view

Step 3 : Connecting all the components together for the line follower

Setup the hardware connections with the arduino and the servo motors. The continuous rotation servo motors are those kinds of servo motors that cannot be controlled or set at a particular angle unlike normal servos. Servos have three wires coming from them : Red- Power , Black -Ground, White/Yellow- PWM /PPM Signal. The left servo motor (white/yellow wire) is hooked up to arduino digital pin 9 and right servo motor (white/yellow wire) to arduino digital pin 10. The black wires of both the motors are connected to arduino GND and the Red wires to the positive terminal of the battery holder.

Easy Line Follower

Arduino connections for line follower

Using Pololu QTR-8A Reflectance array sensor :
If you are using the pololu sensor, and you don’t need all the 8 IR detectors you can remove 2 of them by cutting at the indicated perforation line on the board. The code we are using is only for 6 of them. Then solder some header pins to the board for Vcc, Gnd and signals 1,2,3,4,5,6. Connect the Vcc and Gnd of this sensor to arduino’s Vcc and Gnd. The signals 1,2,..6 are connected to arduino’s analog input pins A0, A1, A2, …A5.

Using custom fabricated sensor array :
If you are using the custom fabricated sensor array, then short the anode terminals of all the IR LEDs together and connect it to the arduino Vcc through a 220Ohm resistor. Next , short the cathode terminals together and connect it to arduino Gnd. Now, connect a 10K resistor to the cathode of each of the IR photodiodes. Short the free ends of all the 10K resistors together and connect it to arduino Gnd. Now short the anode terminals of the IR photodiodes together and connect it to arduino Vcc. Lastly, connect a wire to the cathode of each of the IR photodiodes (between the cathode and the 10K resistor). Connect each of the wires in sequence to arduino’s analog input pins A0, A1,..A5.

Easy Line Follower

Connections for your custom IR sensor array

 Step 4 : Uploading the code for your line follower

The code for the line follower can be found here : DIY_LineFollower. After uploading the code , you need to sweep/move the sensor array over the black line from left to right for roughly 3 seconds. This is done in order to calibrate and find the max and min values for reflectance. After that place the robot on the line and watch the bot follow it. If your using the pololu QTR-8A reflectance array sensor then no significant changes may be required, try to check the values coming from the sensor through the serial monitor. Based on those values adjust the values in the code correspondingly.

For those who made the custom board, find out the rough values of reflectance over the black line and the outer surface. Substitute these values in the code and calibrate it. You can use normal black insulation tape as the line for your line follower. The line follower in action :

Recommended Posts
Showing 100 comments
  • ak
    Reply

    Sir can you please send me an arduinp code via email . my mail address is (aak0930@gmail.com) . thank you.

  • Musab
    Reply

    HEY! SIR im in need of urgent help! plz send me the pictures of your line follower robot here :- musabali314@gmail.com
    i need to see how you attached the servo motors with the wheels and where u put your wires in. i need to see the sensor as well. plz help

  • Tayyab
    Reply

    Sir can you please send me an audrino code via email . my mail address is (tayyabch95@outlook.com) . thank you.

  • Gaurav
    Reply

    Sir its a great help if you could provide the schematic of the circuit.
    Thanks in advance

  • Gautam
    Reply

    HII Sir i want programming of line follower using avr because i dont use motor driver

  • tanish agarwal
    Reply

    hi can you please give the programming of a line follower robot using 2 ir sensor ,arduino uno ,motor shield and 2 motors.please reply soon and i want to ask why the following code does not work—-
    int motor1Pin1 = 3; // pin 2 on L293D
    int motor1Pin2 = 4; // pin 7 on L293D
    int motor2Pin1 = 6; // pin 10 on L293D
    int motor2Pin2 = 7; // pin 15 on L293D
    int sensor1 = 10;
    int sensor2 = 11;
    int sensorstate1 = 0;
    int sensorstate2 = 0;
    void setup() {
    // initialize the digital pin as an output.
    pinMode(sensor1, INPUT);
    pinMode(sensor2, INPUT);
    pinMode(motor1Pin1, OUTPUT);
    pinMode(motor1Pin2, OUTPUT);
    pinMode(motor2Pin1, OUTPUT);
    pinMode(motor2Pin2, OUTPUT);
    }
    void loop() {
    sensorstate1 = digitalRead(sensor1);
    sensorstate2 = digitalRead(sensor2);
    if (sensorstate1 == HIGH) {
    digitalWrite(motor1Pin1, HIGH); // set pin 2 on L293D High
    digitalWrite(motor1Pin2, LOW);
    }
    else {
    digitalWrite(motor1Pin1, LOW); // set pin 2 on L293D low
    digitalWrite(motor1Pin2, LOW);
    }
    if (sensorstate2 == HIGH) {
    digitalWrite(motor2Pin1, HIGH); // set pin 10 on L293D High
    digitalWrite(motor2Pin2, LOW);
    }
    else {
    digitalWrite(motor2Pin1, LOW); // set pin 10 on L293D low
    digitalWrite(motor2Pin2, LOW);
    }
    }

  • Rebecca
    Reply

    hello I am in a Line follower competition and I used 5 IR sensors but the code doesn’t work could you please tell me what’s wrong ?.thanks in an advance ..
    P.S : I’am a beginner ^_^

    #define s0 A0
    #define s1 A1
    #define s2 A2
    #define s3 A3
    #define s4 A4
    #define rmotor 7
    #define lmotor 8

    void setup() {
    pinMode(1,INPUT);
    pinMode(2,INPUT);
    pinMode(3,INPUT);
    pinMode(4,INPUT);
    pinMode(5,INPUT);
    pinMode(7,OUTPUT);
    pinMode(8,OUTPUT);

    }

    void loop() {
    if ( analogRead(s0==LOW) && analogRead(s1,s2,s3,s4==HIGH))
    {digitalWrite(lmotor,HIGH);
    digitalWrite(rmotor,HIGH);}
    else if (s0,s1,s2,s3,s4==LOW)
    {digitalWrite(lmotor,HIGH) ;
    digitalWrite(rmotor,HIGH);
    }
    else if ((analogRead(s0,s4==LOW ) && analogRead(s1,s2,s3==HIGH)) ||analogRead(s3,s4==LOW) && analogRead(s0,s1,s2==HIGH))
    {digitalWrite(lmotor,LOW);
    digitalWrite(rmotor,HIGH);}
    else if ((analogRead(s0,s1==LOW) && analogRead(s2,s3,s4==HIGH)) || analogRead((s1,s2==HIGH) && analogRead(s0,s3,s4==HIGH)))
    {digitalWrite(lmotor,HIGH);
    digitalWrite(rmotor,LOW); }
    else if (analogRead(s0 == HIGH) && analogRead(s1,s2,s3,s4 == LOW) || (analogRead(s0,s2,s3==HIGH) && analogRead(s1,s4==LOW)))
    {digitalWrite(lmotor,LOW);
    digitalWrite(rmotor,HIGH);}
    else if analogRead(s0,s1,s2,s3,s4==HIGH)
    {digitalWrite(lmotor,HIGH);
    digitalWrite(rmotor,HIGH);
    }
    else
    {digitalWrite(lmotor,LOW);
    digitalWrite(rmotor,LOW);}
    }

    • Wahyu Jr
      Reply

      Thank you very much rebeca and his friends

  • ahmed
    Reply

    can you tell me how i write the code of line follower in” micro pro for pic” program ??

  • Raveendra Lokuhettige
    Reply

    I can make the structure , but i can’t coding so can you please send me the code to this e-mail”raveendral123@gmail.com”.Thank you.

  • Khlane
    Reply

    Can you explain all of the code step by step please. Hardware is easy but coding not. Why there are three letters i, j, k. What do they do? What if it follows black line but against purple background instead? What changes do you need to make for background change colour. What if you want it to follow green tape instead. What are the changes you need to make? How to change of the speed of the servos against different background? If you’d go step by step with the code i’ll be able to answer all of these question myself. So can you please explain the code in detail taking your time.

  • Redwan
    Reply

    Hey i am a beginner… i dnt hv that much ideas about robots and arduino.. i m not used to the term Servo motors..or what they say..can i use a geared motor instead?? or both are the same??

  • GOKUL
    Reply

    sir i have used one program for line follower by using arudino demilanove atmega 328 but its not working .here i have used three sensors it moves forward but its stoping at the junction like three sensors are going low but it has to rotae 90 degrees to left and move forward and has to rotate 45 degrees left at another junction can plz plz plz tell me the code how to do it .Thanks in advance
    my program is

    int l,r,s;

    void setup()
    {
    pinMode(10,OUTPUT);
    pinMode(11,OUTPUT);
    pinMode(12,OUTPUT);
    pinMode(13,OUTPUT);
    pinMode(2,INPUT);
    pinMode(4,INPUT);
    pinMode(6,INPUT);

    }
    void loop()
    {
    l=digitalRead(2);
    r=digitalRead(4);
    s=digitalRead(6);

    if(l==HIGH && r==LOW && s== HIGH)
    {

    if (l==LOW && r==LOW && s==HIGH)
    {
    digitalWrite(10,HIGH);
    digitalWrite(11,LOW);
    digitalWrite(12,LOW);
    digitalWrite(13,HIGH);
    }
    digitalWrite(10,HIGH);
    digitalWrite(11,LOW);
    digitalWrite(12,HIGH);
    digitalWrite(13,LOW);
    }
    else if(l==HIGH && r==HIGH && s== HIGH )
    {
    digitalWrite(10,HIGH);
    digitalWrite(11,LOW);
    digitalWrite(12,HIGH);
    digitalWrite(13,LOW);
    }
    else if(l==LOW && r==LOW && s== LOW)
    {
    digitalWrite(10,HIGH);
    digitalWrite(11,LOW);
    digitalWrite(12,LOW);
    digitalWrite(13,HIGH);
    }
    else
    {
    digitalWrite(10,HIGH);
    digitalWrite(11,HIGH);
    digitalWrite(12,HIGH);
    digitalWrite(13,HIGH);
    }
    }
    and i will send the track to your email plz help me sir

  • Simplotrons
    Reply

    Sir, we have used your program for our LDR based LFR. We have modified it according to our need. Your code is great!!. But the problem that we are facing is that, it oscillates left and right too much and skips U-turns. can you tell us that why we have to add and subtract this 30 and in delay function why we have to divide it by 2
    if((((s0+s1+s2)/3)>(((s3+s4+s5)/3)+30))) //Move right
    {
    right();
    delay(abs((((s5+s4+s3)/3)-((s0+s1+s2)/3))/2));
    }

    if((((s0+s1+s2)/3)(((s3+s4+s5)/3)+30))) //Move right
    {
    right();
    delay(abs((((s5+s4+s3)/3)-((s0+s1+s2)/3))/2));
    }

    if((((s0+s1+s2)/3)<(((s3+s4+s5)/3)-30))) //Move left
    {
    left();
    delay(abs((((s5+s4+s3)/3)-((s0+s1+s2)/3))/2));
    }

    }

    void left()
    {
    int b=0;

    analogWrite(lenble,b);
    analogWrite(renble,(b+60));
    digitalWrite(rmotor1,HIGH);
    digitalWrite(rmotor2,LOW);
    digitalWrite(lmotor1,HIGH);
    digitalWrite(lmotor2,LOW);

    }

    void right()
    {
    int b=0;

    analogWrite(lenble,(b+60));
    analogWrite(renble,b);
    digitalWrite(rmotor1,HIGH);
    digitalWrite(rmotor2,LOW);
    digitalWrite(lmotor1,HIGH);
    digitalWrite(lmotor2,LOW);

    }

    void straight()
    {
    int b=60;

    analogWrite(lenble,b);
    analogWrite(renble,b);
    digitalWrite(rmotor1,HIGH);
    digitalWrite(rmotor2,LOW);
    digitalWrite(lmotor1,HIGH);
    digitalWrite(lmotor2,LOW);

    }

    void stops()
    {
    digitalWrite(lenble,LOW);
    digitalWrite(renble,LOW);

    }

  • Samuel D
    Reply

    Hi arvind just asking i want to build a robot like this one but i want to ask if its possible to implement both IR sensors for Line following and Ultrasonic Sensors for object avoidance into the same code and hence on the same robotic vehicle…

  • Bre
    Reply

    It says the code does not work, what should I do?

  • abhi
    Reply

    i am unable to understand the code for a line robot….could u pls provide the code with comment lines???

  • abhi
    Reply

    SIR,if i have two paths emerging from a point i.e black strip, how the robot decides to go in a correct path???

  • Matt
    Reply

    Nice work and awesome tutorial!
    quick question
    left.attach(8, 800, 2200); //left servo motor
    right.attach(9, 800, 2200); //right servo motor
    what does the second and third conditions control?

  • miguel
    Reply

    What would I need to change in order to use the QTR-8RC ? It has a digital out. Thanks!

  • ved
    Reply

    Sir, if i use dc motor with motor driver so how can i modify this code pls help me.

  • ved
    Reply

    Sir can i use arduinodroid for coding for my own arduino

  • Bruce Wilt
    Reply

    Can you tell me how to decrease the speed of the servos in your code. Sensors all seem to be working but the robot starts and stops and then has to re calibrate the line again. Then it will take off in a random direction.

    Thanks

    • Arvind Sanjeev
      Reply

      Hi Bruce,
      Try editing the pwm values sent to the motor.

      • pradeep
        Reply

        can anyone send me program for 2 ir sensor… please

  • abishaan
    Reply

    sir if we use another sensor (eg: line hunting sensor ) will your code work for this sensor

  • ved
    Reply

    Which is more batter for this project a DC motor with LM239 or a servo moter ???

  • ved
    Reply

    It will be work if I will convert a 180 degr. rotation servo into continuous rotation servo

  • MUHAMMAD SAFAR
    Reply

    thank you sir for the post. really enjoy it.

  • TerrenceJ
    Reply

    I forgot to mention in my other posts that if anyone wants a copy of Arvind’s Sketch (code) for this build BUT with the modifications that I made to suite my Home Made Sensor and my Servos then send me an email to; terrencej.banana.pi@gmail.com and I will send it to you. Remember that it is to suite MY setup but it might help you to get yours going or put you on the right track anyway. I also set up the same IR components as in my Bot and tested it on a black background with a white line and I’m 99.9% sure that it would work with the correct sketch modifications to match the voltage levels output from the IR sensor and background/line. It’s All in the Sketch. Cheers, Terry (TJ).
    http://terrencejpiman.blogspot.com.au/

  • naufy
    Reply

    arvind that code doesnot work can you please mail me the code it is for my science fair please. naufrannneyas@gmail .com

    • Arvind Sanjeev
      Reply

      Can you state the errors, I dont have any other code for it.

  • naufy
    Reply

    the code for ir led

  • naufy
    Reply

    dear arvind sir,
    can you please email me the code to
    naufrannneyas@gmail.com

  • abishaan
    Reply

    Bro I made a obstacle avoiding robot now need to make a line follower
    I used a motor shield,adinuo uno
    To make a line follower can pls tell me a suitable line detecting sensor to follow both black and white line

    • Arvind Sanjeev
      Reply

      As said in the tutorial, you can either use the sensor from pololu or equivalents from other manufacturers. Or make your own sensors, like in the tutorial.

  • abishaan
    Reply

    hi bro,
    I’m doing a project on line following robot in that i want the robot to follow the black line in a white background + follow white line in a black background in shortest possible time.It would be great if you help me in this..

    • Arvind Sanjeev
      Reply

      All you need to get started is here in this page, let me know if you want anything more.

  • mat
    Reply

    where i can adjust my line sensor.?it is same use your code..to my custom ir sensor?

  • mat
    Reply

    may i ask..i have make my own ir sensor array…i use the code that have given from you without editing..then i connect all the connections follow the Connections for your custom IR sensor array picture above..
    but,
    its just like nothing happen after i swap the sensor for 3 second.
    can u show me the step for custom sensor..urgent..tq..

    • Arvind Sanjeev
      Reply

      Test the output of each sensor from your array using a black surface, print the outputs on a serial monitor. And see if they work.

  • chris
    Reply

    may i ask why do u use the digitalwrite point 13 at the begining and the ending part(there is nothing connected on this point)? why does it make sense? thanks

    • Arvind Sanjeev
      Reply

      Pin 13 is connected internally to an onboard LED on the arduino. Its used for showing the status of the program that is running.

  • Francheska
    Reply

    Sir, thanks to your detailed explanation and procedures. We are able to accomplish this project. Thanks a lot!

  • Nick Hammond
    Reply

    Hey Arvind, I copied your robot but it just spins in circles and barley follows the line? Any idea on why it would be doing that? Thanks for your time and design!

    • Arvind Sanjeev
      Reply

      Is the robot detecting the black line? You should maybe try decreasing the motor speeds.

      • Nick Hammond
        Reply

        It dosen’t detect the line. I have adjusted the height of the sensor it just spins for about 3 seconds once you give it power, then shoots off in a random direction.

        • Arvind Sanjeev
          Reply

          Check the serial monitor for the data coming from the sensor, and see whether it detects the black portion.

  • Gashaw Debebe
    Reply

    Hi Arvind, you are more than welcome to use the images and video and I can give you the information on the components used etc, the code/sketch is your sketch with the modifications to marry up to my home made IR sensor and motors that I modified, it’s also your wiring diagram that was used to make/set up the sensors etc. What ever you need, it’s all yours to use as you wish

  • francheska
    Reply

    Sir, do we need to change the code if we use dc motor? Thanks!

    • Arvind Sanjeev
      Reply

      Yes, you would have to. You would have to use a motor driver and edit the code for it.

  • TerrenceJ
    Reply

    Well all the bits arrived and I made up the IR sensor array first and did some tests and all worked first time, as I said I had modified the servos for 360 operation, so I put it together on the test bench and spent the next 3 days trying to get the sketch to work with the home made IR sensor and the motors that I modified, I had to make some modifications to the sketch but it worked on the test bench so I put it together today and did some tests and it worked okay, it still needs some work on the sketch to tidy up the operation but it’s working. Thanks for the ideas, sketch etc, it’s been fun making it. I took some photographs as I built it and a video of it in operation on it’s maiden voyage so I’ll put them up somewhere, not sure just where yet. Cheers, Terry.

    • Arvind Sanjeev
      Reply

      Hi Terrence, that’s great news. I would love to post a tutorial of your project on DIY Hacking :)

      • TerrenceJ
        Reply

        Hi Arvind, you are more than welcome to use the images and video and I can give you the information on the components used etc, the code/sketch is your sketch with the modifications to marry up to my home made IR sensor and motors that I modified, it’s also your wiring diagram that was used to make/set up the sensors etc. What ever you need, it’s all yours to use as you wish. Cheers, Terry.

        • Arvind Sanjeev
          Reply

          Hey, please do send me the tutorial at: ars@diyhacking.com :) I would love to post a tutorial in your name :)

          • TerrenceJ
            Reply

            Hi Arvind, I’ll put it together and email it off for you as soon as possible, Cheers, Terry.

          • TerrenceJ
            Reply

            By the way I posted my latest robot builds including my version of this robot on; http://terrencejpiman.blogspot.com.au/ , scroll down the page and you will find the simple line following robot images and story plus a video of the maiden voyage or was it the finished product, anyway it’s a video of this robot. Cheers, Terry, (TJ.)

  • akshay
    Reply

    Sir can u plz post Vedio for the same line follower plz.. And can u post the programming plz thank you

    • Arvind Sanjeev
      Reply

      Sir, everything has been posted in tutorial. Read through.

  • chaudhry zaman
    Reply

    hi Arvind sanjeev
    I am doing project line following robot using Arduino uno microcontroller with two dc motors and using two infra red sensors to follow the path please can u send me the connection diagram and code to run the robot I am using ic to voltage control for dc motors thanks

    • Arvind Sanjeev
      Reply

      I only have the resources currently in this tutorial, please got through it.

      • chaudhry zaman
        Reply

        hi thanks for reply with useful information. one more question I need to detect the obstacles comes on track. I am using arduino uno microcontroller which sensor I will use to detect the obstacles and wat will be the code .

        • Arvind Sanjeev
          Reply

          You can probably use the ultrasonic distance sensor for this :) You can search online for the code.

  • Swarnika
    Reply

    Hey Arvind!

    Would it still work if we use ordinary servo motors instead of continuous rotation servo motors? How about ordinary DC motors or maybe stepper motors?

    Thanks!

    • Arvind Sanjeev
      Reply

      Hi, by ordinary servo motors, if you mean half rotation ones, then no it wont work. However, you can always use DC/stepper motors.

  • TerrenceJ
    Reply

    G’Day Arvind, I have a question re the code, I understand 95% of it but the line just after serial begin “digitalWrite(13, LOW); and then it’s opposite a bit later on in the code, what is it for in the code, I understand that it is turning the on board LED ON and OFF but nothing else is connected to pin D13 or at least not that I can see. This happens a few times through the code but I just can’t see what it is doing other than turning the LED on and off. I got caught up in other projects and I wanted to build this when I first saw it so that I could see the operation of a simple line follower using infrared LEDs and photo-transistors. I now have all the components to make it but wanted to understand the sketch fully so that I would know what to expect during setup of the IR LEDs and transistors. Cheers and Thanks, Terry.

    • Arvind Sanjeev
      Reply

      Hi Terry, the on board LED (13) is turned ON and OFF to denote the stages of the robot. In the first stage it scans the line, the LED is then used to denote that it is scanning and then later too, it is used to notify the user that a particular process is completed. Other than that there is no other reason why the LED is used.

      • TerrenceJ
        Reply

        Hi Arvind, thanks for the reply and I thought it might have been for that but just didn’t have enough experience with writing a sketch to be 100% sure, I’ve decided to make the IR sensor myself and ordered enough components to do so, might take a week or so to get them. I modified the servos yesterday and they work very well, at $10AUD each they are very cheap motors with huge torque. Anyway, thank you very much for the reply, much appreciated, Cheers, Terry.

        • Arvind Sanjeev
          Reply

          Awesome Terry :) Glad that you got started, please do update us with your work (y)

  • Bill Kennedy
    Reply

    Arvind,
    In the “Connections for your custom IR sensor array” schematic drawing, can you help me understand how the forward biased photodiodes work? How does the voltage change when the IR light is shined on it?
    Thanks!

    • Arvind Sanjeev
      Reply

      Hi Bill,
      When the IR light falls on the diode, the diode starts conducting. Consider it to be a switch, when IR light falls on this switch, the switch closes and starts conducting, else it stays open.

  • Tian Goo
    Reply

    Hello sir Arvind!

    I’m done with the connecting of my component but I have another problem. My code does not work.

    so the pins goes like this:

    (from YL-70 sensor)

    IN1 = (digiPin) 7
    IN2 = (digiPin) 8
    IN3 = (digiPin) 9
    IN4 = (digiPin) 10

    (L298N motor driver)

    in1 = (digiPin) 1
    in2 = (digiPin) 2
    ENA = (digiPin) 3
    in3 = (digiPin) 4
    in4 = (digiPin) 5
    ENB = (digiPin) 6

    and my code is this:

    //Define Pins
    int ENA = 3; // “ENA” is pin of L298N motor driver; “3” is Arduino Digital PIN
    int IN1 = 1;
    int IN2 = 2;

    int ENB = 6;
    int IN3 = 4;
    int IN4 = 5;

    int IR1 = 7;
    int IR2 = 8;
    int IR3 = 9;
    int IR4 = 1;

    int leftvalue = 0;
    int rightvalue = 0;

    //Define Run variable
    boolean run;
    void setup() {

    pinMode(ENA, OUTPUT);
    pinMode(IN1, OUTPUT);
    pinMode(IN2, OUTPUT);

    pinMode(ENB, OUTPUT);
    pinMode(IN3, OUTPUT);
    pinMode(IN4, OUTPUT);

    run = true;

    }

    //command sequence
    void loop() {

    if (run){

    rightvalue = digitalRead (IR2);
    leftvalue = digitalRead (IR3);

    if
    ( leftvalue < 80 && rightvalue 80 && rightvalue < 80)
    {
    digitalWrite (ENA, HIGH);
    digitalWrite (ENB, LOW);

    }
    else {
    if (leftvalue 80)
    {
    digitalWrite (ENA, LOW);
    digitalWrite (ENB, HIGH);
    }
    else
    {
    if (leftvalue > 80 && rightvalue > 80)
    {
    digitalWrite (ENA, LOW);
    digitalWrite (ENB, LOW);

    }
    }
    }
    }
    }

    it is not working, but I tried another code and my robot is working but not detecting black lines, it move but it’s movement is fixed.

    Thank You Sir! :)

    • Arvind Sanjeev
      Reply

      Can you check if your L298 is working, that is, is it able to reverse the direction of rotation of the motor?

  • naufy
    Reply

    awesome dude

  • suhail
    Reply

    Iam in malappurram

  • TerrenceJ
    Reply

    I love a simple but rewarding build like this, I will put one together for the grandchildren after I visit the hardware store tomorrow for the wood for the chassis, I have enough of the other bits to put something together for them. Cheers, well done. Terry.

  • suhail
    Reply

    I cant get a aurdino fro online there is no delivery to my place what I do now

  • Tian Goo
    Reply

    Hello sir Arvind,
    Thank very much for your fast response. By the way, here is the link.

    http://www.wayengineer.com/index.php?main_page=product_info&products_id=1076#.VI52ydI73GA

    I’m having problem on where to connect those wirings, or simply the wiring connection. I’m using arduino uno r3, l298n motor driver and yl-70 sensor.

    Thank You Very Much sir. :)

    • Arvind Sanjeev
      Reply

      Hello Tian,
      I think the output from the sensor is digital (4 pins). Why don’t you try connecting the four pins (OUT1,OUT2,…) to arduino’s digital pins and use digitalRead() to read those pins and check if the IR leds are working.

  • Tian Goo
    Reply

    P.S.
    I’m not using servo motor, I’m only using DC Motors connected to motor driver.

  • Tian Goo
    Reply

    Great work sir! but I’m having problem with my robot, because i’m not using the same components like yours, I’m using arduino uno r3 board, l298n motor driver and YL-70 4 cannel IR sensor, I’m having problems with the connection of wirings because I can’t find a schematic diagram of IR sensor that I use. Can you help me sir? It would be a great pleasure. Thank You! :)

    • Arvind Sanjeev
      Reply

      Hello Tian,
      Can you send me any links on the sensor you are using, I will check it out and let you know.

  • Stan
    Reply

    Thanks for this. How would you adapt the code for the QTR-8RC (digital) array?

  • gladwin xavier
    Reply

    i want to know the pgm of line follower ardinos

    • Arvind Sanjeev
      Reply

      Hey, its available on the post, check out the hyperlink for the source code.

  • Pat
    Reply

    Hello
    Great Job!!
    Can you make the line robotand the web cam robot with raspberry pi only?

    Thanks
    Pat

  • jo
    Reply

    Great work dude

pingbacks / trackbacks
  • […] inspiration for your DIY electronics projects at DIYHacking.com. In his May 16, 2014, article, “Make a Line Following Robot in 10 Minutes,“ Arvind Sanjeev explained how you could build a simple robot with Arduino parts and a few other […]

Leave a Comment

− 4 = 1

Start typing and press Enter to search