Ads Below The Title

Make a Line Follower robot from basics


As I promised in my previous tutorial, today I will show you how to make a line follower robot using the basics of our previous tutorials. But before that let’s see what a line follower robot is. A line follower robot is so called because it is meant to follow a particular path or line. The robot detects its path by distinguishing the colour of path/track from the colour of its surroundings. For example, consider the track shown below:








Now in above track, we have a simple black line. This type of track can be made by putting black tape over a white sheet or any other white background. It is not mandatory that you have to use black tape as track and white sheet as a background; I will show you how to make your robot follow any colour track. 
Line follower accomplishes its task of detecting colour by using LDR (light detecting resistors) sensor. We already had a tutorial on LDR sensors where we made a simple circuit that can detect presence of light and darkness.   

I recommend reading that post (click here)before proceeding because it covered fundamentals behind the working of comparator IC LM324. But if you already know what a comparator IC does, keep going.


How LDR tracks the ’track’?

Light detecting resistors are very sensitive to light. Whenever intensity of light increases, the internal resistance of the LDR decreases and current can travel through it with an ease. On the other hand when the sensor is brought into darkness, its internal resistance increases and current faces high resistance (nearly 10M ohm). Our job is to make use of this property to run the robot on desired track. 
The colour black itself holds a property of absorbing light. Whenever light falls on black surface, it gets absorbed and no reflection takes place but on the other hand white colour holds a property of reflecting the light. So, whenever light falls on white surface, it gets reflected. 





Now, what we are going to do is, we will use a light source such as LED to transmit light over the track and an LDR sensor placed near to LED to sense the light. As our track has two colours black and white, when light falls over black surface, light gets absorbed and no reflection occurs and when it falls on white, it gets reflected. This reflected light is sensed by the LDR sensor which in turn instructs circuit to follow the path.
Watch out how the concept actually works:








Making Brain of the Robot:

This is the most important part of any robot, its robustness, and decision making capability depends on the brain. Like human brain controls the movement of body, robot’s brain also instructs its motor when to move forward, when to take a turn and when to stop at a particular point. 

Let’s see what is inside brain of line follower. The first thing we want to make robot capable of, is to detect the colour of the track, to follow a certain track, it must be capable to distinguish between two colours which in our case is black and white. This task is accomplished using LM324 comparator IC. It is capable of taking decisions by comparing two inputs. If you don’t know anythingabout LM324, click here to have a quick overview.

All we need to do is connect the LDR with the LM324 input, provide a reference voltage to the LM324 and we are done with the decision making part. I am just giving you an overview right now; I will show you how to actually connect the LDR to the comparator IC and how to set reference voltage in implementation part till then keep on reading.

The output after the comparison in LM324 is logical 1 (+5v) or logical 0 (ground). Now, to send this output to the motors, we need another IC which is 7404 NOT gate IC. NOT gate in digital electronics is simple gate which inverts the signal provided to it.




 If you feed the NOT gate with logical 1 then its output will be logical 0 and vice versa. This output of the NOT gate IC is what we need to drive the robot.





 
Motor Driver:


Motor Driver is the part of robot which controls the motor. Motor driver is connected with the NOT gate IC, it performs following tasks:

1.      Rotate the wheels in clockwise and anti-clockwise directions.

2.      Apply brakes.

3.      Turning off all the wheels to give motor a free wheel motion.




Motor driver IC we are going to use today is L293D H-bridge IC. L293D is used to drive small motors. It comes in a 16 pin package and is capable of driving two motors simultaneously according to the input. It is called as H-bridge IC because it has an inbuilt H like structure to control the motors as shown below:





The circuit above is an overview of H-bridge present inside the L293D. It has four switches.
1.       If you turn ON switch A and switch D, the motor will rotate clockwise.
2.      Turning switches C and D ON will make it rotate Anticlockwise.
3.      Turing switch A and switch B will immediately stop the robot. (Brake)
4.      And, if you want to try, turning ON switch B and D or switch A and C will make short circuit. 




How robot takes a turn?

Yup, this question often arise because some thinks that it does not have any steering wheel or anything like that to take a turn than how the hell will robot change its direction. Well, the robot takes turn by switching motors. This switching is performed by motor driver IC. Consider we have two motors, a left motor ‘L’ and a right motor ‘R’.

1.      If L and R are moving clockwise, robot will move forward.

2.      If L and R are moving anti clockwise than of course robot will move backwards.

3.      If L is moving clockwise and R is turned OFF then robot will take a right turn.

4.      If L is turned OFF and only R is moving clockwise then robot will take a left turn.

5.      If L is moving clockwise and R is moving anticlockwise, then robot can rotate 360 degree on the same place and vice versa.

So, now we know what different sections will do and what is needed, we are ready to start implementing our very first robot.
  

Components Required:

1.      Chassis
Our whole circuit and the battery will be placed over chassis. It comes readymade but you can also use a toy car having two motors. To do so, remove all the fancy part of toy car so that you are only left with two motors connected to wheels. Solder two wires at the terminals of wire and you are done. My own Toy car chassis is shown below:




1.      Breadboard,
With complete Power supply (Click here to have a quick view on how to make a power supply)

2.      Through hole PCB, Solder Iron, Solder wire.

3.      Two LDR sensors,
To sense the colour of the track.

4.      Resistors,
Two 10k ohm resistors for LDRs.
Two 125 ohm resistors for LEDs

5.      LM324 comparator,
To take decisions over colour detected by the LDR.

6.      7404 NOT gate IC.
To invert the output signals given by LM324.

7.      L293D motor driver IC.
To steer the robot.

8.      A track,
Over which our robot will do stunts. Take a black tape and stick it over the white sheet. The white sheet you are using should be large enough and the tape you are sticking should not have sharp turns. Make it like one shown at the beginning of this tutorial or watch the video at the end of this post that shows my own robot.




Step 1:
 
The first thing we are going to do is making a sensor-LED pair. It is recommended that you use white light LED as they have high brightness. Now take you through hole PCB and solder the LDR and 10k ohm resistor and LEDs with 125 ohm resistor like circuit shown below:




Remember that LED and sensor are near to each other. The output of the LDR is taken from any of its two legs, solder a wire of around 15 centimetres (so that output can reach into potentiometer comfortably) and do the same at the other LDR-LED pair. See the actual picture of my PCB showing the connection:





Step 2:

Right now we have two wires in hand emerging out of the LDR sensors which are the output of both LDRs. Now we will compare this output with some reference voltage. 

The comparison is made so as to make certain difference between the white and black colour of the track. For example, you have set some reference voltage, say 3 volts. This is fix voltage to which we will compare the output voltage of LDR.

 Now, the output of the LDR depends upon the light that is falling over it. If your LDR is placed in dark then it will have large resistance across it and will allow small current (logical ‘0’) to pass through it but if placed in light, resistance will go down and maximum current can pass through it (that is logical ‘1’). So, the LDR has two outputs, either low voltage (it should be around 1.5 to 2.5v) or high voltage (4.5 to 5 volts). 

Now comparison helps in distinguishing between the colours of the track. When the LDR is facing black strip of the track, it will give output of around 2 volts which is less than our fixed voltage (3 volts) and hence output of the comparator IC will be a logical ‘0’ and when the LDR face white sheet, the output of LDR will go high (5 volts) which is more than the reference voltage (3 volts) and hence output of the comparator will be logical ‘1’ (that is 5 volts).
This is how our robot differentiates between the colours.

Now insert the LM324 IC near to the corner of breadboard. Give the power supply and ground to the IC’s pin number 4 (‘+’) and pin 11 (‘-’) as shown in the picture below





Step 3:

Now to give a reference voltage, we will use potentiometer. Insert the two potentiometers near to the LM324. Take care that you insert the potentiometer correctly do not overlap its pin with the pins of LM324. See the picture below that shows how actually you have to put in the potentiometers.




The IC LM324 has four inbuilt comparators that mean you can compare four independent inputs. But right now we have two sensors, we will use two comparators and hence we are using two different potentiometers for setting reference voltage. 

If you have connected the potentiometers near to the LM324, proceed to next step that shows how to interface LDR and potentiometer with comparator.



Step 4:

Before interfacing, connect the pin 1 and pin 3 of both the potentiometers with Vcc and ground respectively. Now connect the output pin (2/middle one) of potentiometer with the pin number 3 of the LM324. This is non inverting pin, which means that the input given to this pin is taken as it is while at the inverting pin (pin no. 2 of LM324) the input is first inverted (high to low or vice versa) and then taken inside. 

Connect the output from the left LDR with pin number 2 of LM324 IC. Hence you can see that you have two inputs connected to the LM324. One is reference voltage at pin number 3 and another is output coming from the LDR. 

We have successfully interfaced left LDR with the comparator. Now its time to interface the right LDR and potentiometer. Connect the output from the second potentiometer with pin number 5 of the comparator IC and pin number 6 with the output of right LDR. 

That’s it our comparator part is complete, all we need to do is take the output of the comparison and feed it to the next IC which is 7404 IC.

Step 5:

The IC 7404, as I explained before, is meant for inversion of signals or input given to it.
Insert the 7404 IC next to comparator IC. It is good practice to keep a possible minimum distance between the two components, it will help you when you will work on PCB but before that try becoming pro in making breadboard connections. 




After inserting the IC, give its pin number 7 ground and pin 14 Vcc.

Connect the output comparator output pin (pin number 1) with the pin number 1 of the IC 7404. This inverted output will be produced at pin number of inverter IC with which we will deal in next step.

Similarly connect the second comparator’s output from pin number 7 of the LM324 with pin number 9 of the 7404 inverter. If you see the internal gate structure of the NOT gate IC, you will notice there is a not gate present between pin number 8 and 9 that’s why I have taken pin number 9 of the inverter IC because it will help in reducing complexities in circuit. You can take any inverter by observing the internal figure of 7404, it has six inbuilt inverters.


Step 7:

We have completed making the brain of robot. It’s time to use this brain by connecting it to motor driver IC L293D.

Place the L293D near to the inverter IC. 





Connect the chip inhibit pins i.e. pin number 1, pin number 9 and power input pin number 16 to Vcc (‘+’). 

Connect pin 4, 5, 12, 13 to ground. There are more than one ground and Vcc in this IC, they are actually meant for providing ground to motors and the IC itself. 

Now, check out the internal overview of L293D, you will notice, there are four inputs and outputs. We have to connect output of the inverter IC 7404 at the pins marked input i.e. pin number 2, 7, 10, 15. 

But here a question arise, we have only two outputs from the 7404 IC and we need four inputs to operate motors at L293D. The answer is that for a single motor, two inputs are required. For example, say you want that left motor should start rotating as soon as you apply power to the circuit. To do so at input 1 we provide non-inverted input and at input 2, we will give an inverting input. This will make the left motor working connected at pin output 1 and output 2.

Here, the inverted input will come from the pin number two of IC 7404 and the non inverted output is taken from the pin number 1 itself. 

When you finish making connection at the left motor, do the same for right input pins of motor driver.



Step 8:  

It’s time to connect motor to the L293D, well it is pretty simple, insert the left motor’s wire at output pins (pin number 3 and 6) and similarly connect the right motor with output pins 11 and 14 and you are done. 

The only pin left is pin number 8 of motor driver which we haven’t used till yet, well it is the input for motors. If you are using a 9 volts battery then directly connect the positive terminal of the battery to this pin. You can apply an input up to 36 volts at this pin, depending up on amount of voltage you motors can intake.

That’s it you have just now created a pretty smart robot without using any microcontroller or coding stuff. If you have any doubt on you robot that it will not work like those working on microcontroller bots, watch out my own robot in the video below:


Step 9:

The step 9 is about assembling everything you made. To do so, take you chassis, if you have one similar to my chassis then its fine, but if you don’t have one, you can take a toy car having two motors. 

Now, take some tape or glue to stick the PCB at the front side of the robot. It is recommended that it should not be more than 5 cm from the ground. See the figure below showing how to fix the PCB.







Extend the wires that give Vcc to the LED and LDR, insert them into 5 volts supply of breadboard. Do the same for providing ground to them. When you will power up the circuit, the LED’s will glow and using multimeter you can check whether LDRs are working or not.

After this, fix the breadboard to chassis so that it does not move off its position when robot is working.
So, now you can put the robot over the track, connect the battery and see the robot following the track.



Convert this robot to follow White line:

To do this, insert the LDR output pin in pin number 3 that is non-inverting pin and the output of corresponding potentiometer into inverting pin (pin number 2) of the LM324 comparator. Apply same actions for second LDR’s output and its corresponding potentiometer. Your robot is now configured to follow white line.


Change the robot’s configuration to follow any colour track:

Let’s say you want to make a robot following red track over yellow background or any other light coloured background. Follow the steps below:

1.      Take a small strip of red colour (or the colour your track is made up of). Turn on your robot and put the strip below the LDR.

2.      Using multimeter, measure the output of the LDR, say it is 1.5 volts.

3.      Now take the strip of your track’s background colour. Put it in front of LDR and measure the output of LDR, now its output will be approx 4 volts (or whatever it comes).

4.      Now add the outputs in both the cases i.e.


1.5 + 4 = 5.5 volts.

Divide this by 2:

5.5/2= 2.75 volts.

Adjust the potentiometer output pin, so that output is approx 2.75 volts.

5.      Take your robot to the track and BOOM it will start working over your fancy track.


Common Problems faced while making Line follower robot:

1.      The LED and LDR pair is not working.

Ans: You have to provide Vcc to them, also check the polarity of the LEDs, LDR are bipolar devices.

2.      My robot senses the colour occasionally.

Ans: Here the potentiometers are not adjusted, try setting its output put pin to approx 3 volts.

3.      My motor driver IC gets heated up and motors moves very slowly.

Ans: Remove the Vcc supply immediately and check for the connections at L293D. Always use a multimeter to verify connections.

4.      Nothing is working at all. What the FUUUU....

Ans: hehe...calm down it happens, check out if all the pins you have connected are correctly inserted in the breadboard and also sometimes IC’s pops up from their place.

5.      One motor rotates in clockwise direction and other one in anti clock wise direction or The motors are not rotating in my desired direction.

Ans: Just change the polarities of motor wire at the output pins of L293D.

6.      I have some other query; this whole goddamn crap is annoying me.

Ans. Yup, ask them in the comment section below and I will surely reply. You can also visit my facebook page and ask your queries there. Go to: www.facebook.com/letslearnelectronics

Okay then.... That is all for this post, in next post I will show you how to make a simple Obstacle detector robot using the same circuit of what we made today.

Till then Good Bye... :) 

Make a Line Follower robot from basics Make a Line Follower robot from basics Reviewed by haru on August 22, 2012 Rating: 5

No comments

Ads Inter Below The Post
Image Link [https://lh3.googleusercontent.com/-wlvSkBWGUW0/AAAAAAAAAAI/AAAAAAAAAxU/6FpWSjn-h2o/s120-c/photo.jpg] Author Name [Sora Templates] Author Description [Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard] Facebook Username [#] Twitter Username [#] GPlus Username [#] Pinterest Username [#] Instagram Username [#]