Make Line-follower Robot using Arduino and IR sensor array


Let sensors do the work:

Till now, we have made proximity sensor, which can be used for obstacle detection or following a black line on white surface (How and why? Ok, think about it. I will answer it a little bit later). But I want to let you people know one thing that in higher level of robotics, we don’t make sensors of our own (obviously you can make them for your hobby and interest. But DON’T USE THEM in your robots as hand-made sensors in most cases lack of accuracy and can make your robot prone to malfunction), instead we buy them in ready-made version as they are pretty much available in market in various price and accuracy range. We simply buy them and put them in our robots.
Now, as we proceed to the making of Line-follower Robot,let me answer some basic questions about Robotics.

What is a Robot?

The instruments with artificial intelligence, which follow these 3 basic rules strictly can be called "Robot".
1)A robot may not injure a human being or, through inaction, allow a human being to come to harm.
2)A robot must obey the orders given it by human beings except where such orders would conflict with the First Law.
3)A robot must protect its own existence as long as such protection does not conflict with the First or Second Laws.
These are called "The Three Laws of Robotics",devised by Science Fiction Author Isaac Asimov.

What sensors do in robotics?

What sensors do in robotics is that they make your robots smarter and recognize more activities in their surroundings and do something accordingly.

Let's make a Line-following Robot:



As, in the previous paragraph, I said you can use proximity sensor to recognize a black line on a lighter background. But, how does it do so? Actually, here when IR rays fall on black and lighter surface, black surface absorbs more IR light-rays than the lighter does and obviously reflects less amount of rays than lighter colored surface.


This makes a slight change in the voltage in the resistance connected in series with the Photodiode(for details, read about proximity sensor. Link - https://techie-rka.blogspot.in/2018/04/make-proximity-sensor-in-10-minutes.html) and we can recognize this change through calibrating our potentiometer (100k required) to an exact value of resistance. This is how proximity sensors can sense black and white surface (actually darker and brighter surface in broader sense). But, how the IR sensor array helps in following a specific line will be discussed in the Circuitry part and Coding part.

Let’s make it:

Requirements:- 

1)IR sensor array of size 2(or simply 2 proximity sensors) or 3 or 5 or 8
2)Arduino UNO or Genuino UNO
3)L298N(Recommended) or L293D motor driver module
4)2 wheeled or 4 wheeled chassis
5) Motors - 2 or 4(according to your chassis. Number of motors=Number of wheels)
(In many cases, when you buy chassis,you get motors in-built,so check it before buying extra motors)
6) Batteries or any other power source to run motors.
7)Digital Multimeter (to check circuit,you may need a multimeter too)
(Links- https://amzn.to/2qnSH9chttps://amzn.to/2Hdkmn8https://amzn.to/2HfdMg0https://amzn.to/2GT1Tc1 )
For testing and experiment, you may also need some white A1 paper and black tape to produce black line on white surface.

Now,let's start making:

At first, make the robot body by assembling the robot chassis, motors, wheels and clamps(if needed).
Then if your chassis is of two wheels, add the caster and ball to your chassis and complete it.
If your chassis is of 4 wheels, connect two motors of left side with each other in same sense of rotation(i.e. , they should rotate in the same clockwise or anti-clockwise direction if connected to same voltage source in parallel connection. You can easily check it and manipulate its connections if needed)
So, now ,as the body of our robot is ready, let's add sense(sensors) and  brain( Microcontroller ...LOL...Don't get me wrong) to it.
In this step,  I think you have got lots of free space on the top of your chassis. Add an arduino, L298n motor driver (not L293d,if its a 4-wheeler chassis. As, in practical case, we have seen L293d cannot take too much load and it does not have in-built facility of PWM and its Power efficiency is also low) and a small breadboard. Now add the IR sensor array in the front of your robot and stick with a double tape. In this case, you should ensure that the IR sensor array has got almost perfect central and horizontal alignment. Also ensure that its height from the surface is not more than 1.5 inch(otherwise it can malfunction). 
Now, our chassis-making part is fully completed. Let's get to the circuitry part.

Make the following circuit.



Although the circuit diagram is quite clear, to avoid any confusion, I am listing all the connections made above in a list:
1)Arduino GND-Battery(or other power source for driving motors)(12V) GND-L298(or L293) Motor Driver GND
2)Arduino 5V-Motor Driver VCC-Enable 1- Enable 2
3)OUT 1,OUT 2-Right Motor
4)OUT 3,OUT 4-Left Motor
5)IN1-11
6)IN2-10
7)IN3-6
8)IN4-5
When you're done with all these stuffs, proceed to the coding part. Only this coding part will be different for IR sensor array of size 8,5 and 2. When you will opened the code, you will find the Pin numbers are given for IR sensor array. Connect the IR sensor array strictly according to that. Also here, I am giving the details for connecting the IR sensor array.
For IR sensor array of size 8:
The pins are: {A0,A1,A2,A3,A4,A5,8,9} (Aligned from left to right)
For IR sensor array of size 5:
The pins are: {A0,A1,A2,A3,A4} (Aligned from left to right)
For IR sensor array of size 3:
The pins are: {A0,A1,A2}
For IR sensor array of size 2:
The pins are: {A0,A1} (Aligned from left to right)
So, finally we have completed the circuitry.
Now, let’s talk about the logic of the bot and after that we shall move to the coding part.

Understanding the logic:

So, now we know, by the IR sensor array, we can recognize black and white line, which also implies that we can detect the position of black line with respect to the bot. So, now we have to think about various possible positions of black line with respect to the bot and what our bot should do at those situations.
Now, there is slight difference of logic for Bot with IR sensor array of size 8 or 5 or 3 and Bot with 2 IR sensors. When the Bot is on the top of the black line symmetrically or in centrally aligned position, for bot with 2 IR sensors, each sensor should sense white, while for the bots with IR sensor array of size 8 and 5,only the central portion of the array sense black and rest of the sensors sense white.
Position 1:


In this case, Robot is almost on the top of the black line symmetrically, so here the bot should go ahead straight.
Position 2:


In this case, the left portion of IR sensor array should sense black, while the right portion should sense white. In this case, the bot should take a left turn to adjust its position with respect to the black line.
Position 3:


In this case, the right portion of IR sensor array should sense black, while the left portion should sense white. In this case, the bot should take a right turn to adjust its position with respect to the black line.
These were 3 basic positions for the bot. Now, we should consider some more consequences:
1)What if the bot has moved away from the line, i.e., each sensor senses white? In this case, we move our bot backwards in expectation to get the black line again.
2)What if it has struck a T-shaped joint or cross joint, i.e., all sensors sense black? In this case ,we can move our bot in either left or right position.

Let's code it:

Now, let’s move to the coding part. On the basis of the logic above, I have made three Arduino codes for your bot. They can work with both 4 wheeled and 2 wheeled chassis and with both L293D Motor Driver and L298N Motor Driver.    
I have uploaded that Arduino codes in a folder in Google Drive. You can easily download it.
Here is the link: https://drive.google.com/drive/folders/1TXzQ_Tl1bcGthja30UfEkEzw3Tack2Zd?usp=sharing
For those who are facing problem with Google Drive can download the files from this link too.
Link: http://www.mediafire.com/file/9ts45rdn4hgou0t/Line_follower_Robot%28Techie-rka.blogspot.in%29.zip
So, now as you have uploaded the code to your Arduino, you have to calibrate your IR sensor array by adjusting each potentiometer to detect black and white line. Once, you’re done with this, you have completed making of the Line-follower Bot. Congratulations!!!

If you like this post, please upvote, comment, follow, share and subscribe. Thanks in advance.




Comments