Autonomous Line Following Robot
by Robotics club of CEG in Circuits > Arduino
615 Views, 3 Favorites, 0 Comments
Autonomous Line Following Robot
If you are looking at this page then probably by now you might know what a line tracer robot is. But for those who don't know about it, it is a robot which traces/follows a black line in a white background autonomously. As it says Autonomous robot, it doesn't require human intervention. To be simple it thinks on its own and executes the process based on its coding script, in our case it follows the line. We use infrared transmitter and receivers to detect the black line along with motor driver modules and Arduino to build a line following robot. the process of assembling an line following bot is given in the below steps and video.
Components required:
- IR pair.(IR transmitter and receiver.) - minimum of 3 pairs
- L293d motor driver module. - one quantity.
- Motors. - Two nos
- Castor Wheel. - one quantity
- Arduino board(Any type of board would suffice). - one quantity.
- Wheels - Two nos
- Chassis - one.
- Resistors (220 ohms, 1K ohms, 10K ohm).
- Jumper cables.
- Dot board. - one quantity.
- Berg strips(Male and Female).
IR Module
An autonomous system or any other system in this universe needs one thing, the INPUT to process. In our autonomous bot we are going to use IR pairs as input devices. Got a question why we are using IR sensor? I'll give you a small explanation for that. We might have studied black body radiation. if you haven't then chill. It means that Black objects absorb infrared rays more than any other colored objects. This is the reason why we feel more hot than others when we wear a black shirt on a sunny day. Coming back to the our bot, when IR rays from the transmitter fall on white surface it, most of the Ir rays get reflected back and to receive the reflected IR ray we use the IR receiver. Likewise when IR rays are incident on the black line most of the IR rays are absorbed by the line and very few is reflected back to the IR receiver. Now what does this has to do with our bot?. The IR receiver produces an output voltage equivalent to the amount of rays received. Now lets build our own IR module. In this tutorial we are going to build an analog IR sensor. I'll be using the notation Tx to represent transmitter and Rx to represent receiver.
Like food to us, both the Tx and Rx require power to work. We will be providing a power supply of 5 volts. We provide 5 Volt supply to both Tx and Rx through a resistor to limit the amount of current entering the Tx and Rx. This is because both the Tx and Rx have a limit to the amount of current they can handle, which will be given by the manufacturer. Therefore We will be using 1K ohm resistor with the Tx and 10K ohm resistor with the Rx. From the diagram, we can see the circuit connections of the IR sensor. We are taking the output from the receiver and we are giving it to any one of the analog pins in the arduino. Similarly like this we need to make two or more sensors like this and feed the output from the sensors to the arduino.
Motor Driver Circuit (L293d Driver)
So why do we need an motor driver circuit? It's obvious isn't it ? TO RUN THE MOTOR. But why use a motor driver instead of the arduino directly?. Here is the explanation. The Arduino board cannot produce sufficient amount of power to drive two motors or even a single motor for instance effectively. That's why we go for a motor driver. It is basically an IC(L293d). you can see the pin configuration of the IC. The IC is split up internally into two parts, that is to control two motors separately. That's why we got two enable pins(E1 and E2). The pin Vss is to power up the entire IC. Most ICs are powered by only 5V. The Vs pin is given with a supply required to run both your motors. There are two types of motors. As shown in the pictures the yellow is a micro geared motor(BO motor) and other one is the DC gear motor. Normally we use 12 Volts to run the DC gear motor and about 9V to run the BO motor. BO motors will run on 12V but you will have to control the speed of the bot through your coding, plus the lifespan of your BO motor might be reduced. As for the other pins we give inputs(I1, I2, I3, I4) from our Arduino board to the IC. Every input has its corresponding outputs(O1, O2, O3, O4). To explain the working i'll give you an example. For a motor to run we need to give positive supply to one terminal and negative supply to the other terminal. So i give I1 as HIGH(which corresponds to 5V from arduino) and I2 as LOW(which corresponds to 0V). what happens is your motor will be supplied with the power supply we connected in the Vs pin(which maybe 12V or 9V depending on your motor). Connect the rest of the connections as show in the diagram.
Chassis
You need a chassis for your bot. That is a body where you can fix your motors sensors and arduino boards and motor driver circuits. There are alot of chassis available for line tracers. Some are available in ready-made stores. But you can even build your chassis using mica boards and like that. I'll leave the designing of your chassis to your imagination. But design it with care so that it can house all your components correctly.
Arduino Coding.
If all the above steps are done perfectly then this step is a piece of cake. If you are new to the Arduino software then download the software from arduino.cc . After that you will have to choose the type of arduino you are using and the port in your laptop to which the arduino is connected. You can find the port through your device manager window. Before you could start writing programs and executing some you'll have to update your arduino Software.
Coding part:
Every arduino program requires two main functions.
1. Void setup
2. Void loop
Void setup function is used to denote whether we are using a pin as output or input. For example, we are getting output from sensor and give it to arduino. This means that we giving input to arduino.
Example Code:
void setup()
{
Serial.begin(9600);
pinMode(A0,INPUT);
}
Serial.begin(9600) denotes the rate at which your computer and arduino communicates. It uses serial communication. But for beginners dont forget to use this line in your setup function. I am getting the output from the sensor and giving it to the pin A0. I am denoting to the arduino that A0 is used to get input from outside devices.
SYNTAX: pinMode(pin no, INPUT/OUTPUT);
(Note: Every keyword is case sensitive.)
So for the out put lets say i ll use these two instructions
digitalWrite(pin no,HIGH/LOW); (NOTE: This is when we use digital pins and can give either high power or low power to the motors in our case.)
analogWrite(pin no, 0-255); (NOTE: This is when we use analog pins and we can vary the amount of supply given as result of which we can control the speed of the bot. This is known as pulse width modulation.)
I'll give a small example for a motor running
void setup()
{
Serial.begin(9600);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
}
(NOTE: We use INPUT for getting values and OUTPUT to give values.)
void loop()
{
digitalWrite(5,HIGH);
digital(6,LOW);
}
For the above code your motor may spin either forward or backward depending on your motor's polarity.
To read the values from the sensor we use these two functions
analogRead(pin no);
digitalRead(pin no);
As the name implies, the former is used to read analog values and the latter is used to read digital values.
example:
void loop()
{
int a=analogRead(A0);
delay(500);
Serial.println(a);
}
The above code read the value from sensor and displays it. the delay function works in milliseconds. Thats is delay(500) produces a delay of half a second. Serial.println(a) displays.
For starter you can start by using three IR sensors in your line follower bot.
Their placement is like this.
Left - Middle - Right.
The distance between these sensors should be minimum of 3 cms. I'll give an example code for your robot to go straight.
(I am assuming that my sensors give values less than hundred when they are in the black line.)
// - The contents after these two slashes is for ur understanding purpose and not a part of the code!
Void setup()
{
Serial.begin(9600);
pinMode(A0,INPUT); // left sensor.
pinMode(A1,INPUT); //middle sensor.
pinMode(A2,INPUT); // right sensor.
pinMode(5,OUTPUT); // wire 1 of the first motor. Which is taken from the motor driver module.
pinMode(6,OUTPUT); // wire 2 of the first motor. Which is taken from the motor driver module.
pinMode(7,OUTPUT); //wire 1 of the second motor. Which is taken from the motor driver module.
pinMode(8,OUTPUT); //wire 2 of the second motor. Which is taken from the motor driver module.
}
Void loop()
{
L=analogRead(A0);
M=analogRead(A1);
R=analogRead(A2);
If(M<=100)
{
digitalWrite(5,HIGH);
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
digitalWrite(8,LOW);
}
else // if middle is not in the black line then the bot will stop.
{
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
}
This is a basic code for a line follower bot. For coding the other two sensors I'll leave it to your coding skills.
Your program will change depending on the track so be cautious while coding your not during a event.
After you finish your code then your line follower bot is over. My personal advice is to have two or more backup sensors if you are going to participate in a event. Have backup for absolutely everything and you'll be fine. So that's it for now. See the video if you need a video tutorial. Stay tuned to Robotics club of clg and next time we'll come with something awesome!!!