In this tutorial, we will be learning how to assemble a Line Follower Robot
Our main aim is to assemble a Robotic Car with 2 Motors and one Castor Wheel so that its motion can be controlled using IR Sensors mounted on it which are used to distinguish between black colored path and white surface..
For reference, check the image in Figure1 below:
for Assembling a Robotic Car, we will need following components:
- 1 x Chassis
- 1 x Castor Wheel
- 2 x DC BO Motors
- 2 x DC BO Motor Wheels
- 4 x Single Strand Wires
- 1 x Arduino UNO with USB Cable
- 1 x Motor Driver Module
- 10 x Male to Female Jumpers
- 10 x Female to Female Jumpers
- 2 x Analog IR Sensors
- 1 x Quad IR Sensor Shield
- Screws, Nuts and Bolts
Once all the components are available, we can assemble our robotic car as shown in Figure 2 below:
Once the assembly of Robotic Car is complete, attach the Battery Snapper to Motor Driver Module and mount it on chassis using a single Nut and Bolt as displayed in Figure 3 & 4 respectively
After mounting Motor Driver Module on Car, bend the LEDs of both the IR Sensors by 90 degrees as shown in Figure 5 and after that mount them on Chassis Slots as shown in Figure 6 below:
Once both the sensors are mounted over chassis, mount Quad IR Sensor Shield and Arduino UNO on it as shown in the figure below
Now, as all the components are mounted on chassis, we will start making connections. Following are the Connections:
- Connect Left Motor and Right Motor to Green Connectors on Motor Driver
- Connect sig, Vcc and GND Pins of both IR Sensors to respective d0 and d1 pins of Quad IR Sensor Shield respectively.
- Connect Vcc and GND Pins of Quad IR Sensor Shield with 5V and GND Pins of Arduino UNO respectively.
- Connect d0 pin of Quad IR Sensor Shield to digital Pin no. 2 of Arduino UNO
- Connect d1 pin of Quad IR Sensor Shield to digital Pin no. 3 of Arduino UNO
- Connect Digital Pin Number 4&5 of Arduino Uno with Pin Number 1&2 of Motor Driver respectively.
- Connect Digital Pin Number 6&7 of Arduino UNO with Pin Number 5&6 of Motor Driver respectively.
- Connect 1xGND pin of Arduino to Negative Supply terminal of Motor
After making all the connections, your robotic car is ready to upload the Line Follower Robot code.
Now, we can upload the Line Follower Code by connecting Arduino UNO Board to PC/Laptop as shown in Figure 8 below:
After connecting Arduino Board to Laptop, upload the following code to it:
int s1=0; //variable to store values from left IR Sensor
int s2=0; //variable to store values from right IR Sensor
void setup()
{
// put your setup code here, to run once:
pinMode(2,INPUT); //initialize digital pin no.2 as input of left
pinMode(3,INPUT); //initialize digital pin no.3 as input of right
pinMode(4,OUTPUT); //initialize digital pin no.4 as output
pinMode(5,OUTPUT); //initialize digital pin no.5 as output
pinMode(6,OUTPUT); //initialize digital pin no.6 as output
pinMode(7,OUTPUT); //initialize digital pin no.7 as output
}
void loop()
{
// put your main code here, to run repeatedly:
s1=digitalRead(2); //read values coming from left sensor
s2=digitalRead(3); //read values coming from right sensor
if(s1==HIGH) //check if left sensor is on white surface
{
digitalWrite(4,HIGH);
digitalWrite(5,LOW); //rotate left motor forward
}
else
{
digitalWrite(4,LOW);
digitalWrite(5,LOW); //stop left motor
}
if(s2==HIGH) //check if right sensor is on white surface
{
digitalWrite(6,HIGH);
digitalWrite(7,LOW); //rotate the right motor
}
else
{
digitalWrite(6,LOW);
digitalWrite(7,LOW); //stop right motor
}
}
**After uploading this code, you can power up Motor Driver and Arduino UNO on a black line and your robot will follow the path automatically.**
All the products used in this project can be purchased from following links:
Chassis
Motor Wheels
Caster Wheel
DC Motor
Arduino UNO R3
Quad IR Sensor Shield
Analog IR Sensor
Motor Driver Module
Female to Female Jumpers
Male to Female Jumpers