Arduino Based Line Tracker Robot

29K2725

Intro: Arduino Based Line Tracker Robot

Line trackers are one of the most prominent kinds of robot. they have been existed for very long time and usually for beginners in robotics this is the best project you can play with since this robot has some basic functions and basic programming.

A line tracker robot is a robot able to detect and track a line (black) even if the path is altered by changing the shape of the line. this type of robot has a simple task, and doesn't require strong skills in programming and electronics.

STEP 1: STUFF REQUIRED:

HARDWARE:

  • Arduino Uno
  • 1x IR Sensor Module
  • 1x L293D Motor Driver IC
  • Robotic Platform / Chassis
  • Breadboard / PCB ( It's up to you )
  • 2x DC Motors
  • 1x Castor Wheel
  • 2x Wheels
  • 1x 12V Battery
  • 1x 9V Battery
  • And finally some connecting wires

SOFTWARE:

  • Arduino IDE : ARDUINO

STEP 2: HOW IT WORKS:

The robot has five infrared sensor module attached at the front of our robot that detects from where the light reflects back. that information is used to decide whether to continue straight or to change the direction of the motors to turn accordingly.

Working of line tracker is very simple and interesting. line tracker senses black line by using sensor module and then sends the signal to arduino. then arduino drives the motor according to the sensors' output.

FUNDAMENTAL LOGIC OF LINE TRACKER:

A Dark object reflects less light than a bright object, or we can also say, a dark object absorbs more light than a bright object, this is the only fundamental logic behind a line tracking robot. so, in a line tracking robot, we use a sensor that detects the difference between bright and dark objects, or simply, distinguishes a black line from a white surface.


STEP 3: MAKING CONNECTIONS AND ASSEMBLING THE ROBOT:

Look over your robotic platform / chassis and decide how you would like to assemble it. It's all up to you, either you can make an open and exposed version of your line tracker using breadboard connections or you can go with an enclosed and sorted wiring style like I did using PCB. However, I preferrd to choose enclosed and sorted version for my line tracker and tried to give a unique and different look to my line tracker robot.

I have also made a motor driver shield which is directly connected to the arduino uno board as per the connections ( shown in above figures ).


Make the connections as follows:

  • ARDUINO VCC - SENSOR MODULE VCC
  • ARDUINO GND - SENSOR MODULE GND
  • ARDUINO DIGITAL PIN 12 - SENSOR MODULE S1
  • ARDUINO DIGITAL PIN 11 - SENSOR MODULE S2
  • ARDUINO DIGITAL PIN 10 - SENSOR MODULE S3
  • ARDUINO DIGITAL PIN 9 - SENSOR MODULE S4
  • ARDUINO DIGITAL PIN 8 - SENSOR MODULE S5

And connections for motor driver is shown in above figure.

STEP 4: ARDUINO PROGRAMMING:

Upload the given code to your Arduino Uno board and get ready for the ACTION !

#define lmotorf 4 //Motor A1
#define lmotorb 5 //Motor A2 #define rmotorf 6 //Motor B1 #define rmotorb 7 //Motor B2

//HIGH white //LOW black

void setup() { pinMode(lmotorf,OUTPUT); pinMode(rmotorf,OUTPUT); pinMode(lmotorb,OUTPUT); pinMode(rmotorb,OUTPUT); pinMode(8,INPUT); pinMode(9,INPUT); pinMode(10,INPUT); pinMode(11,INPUT); pinMode(12,INPUT); pinMode(13,INPUT); }

void loop() {

int sensor1=digitalRead(8);//sensor1 int sensor2=digitalRead(9);//sensor2 int sensor3=digitalRead(10);//sensor3 int sensor4=digitalRead(11);//sensor4 int sensor5=digitalRead(12);//sensor5

if((sensor2==LOW)&&(sensor3==LOW)&&(sensor4==LOW)) //When ALL ARE on WHITE line {

digitalWrite(lmotorf,HIGH); digitalWrite(rmotorf,HIGH); digitalWrite(lmotorb,LOW); digitalWrite(rmotorb,LOW); } else if((sensor2==HIGH)&&(sensor3==LOW)&&(sensor4==HIGH))

{ digitalWrite(lmotorf,HIGH); digitalWrite(rmotorf,HIGH); digitalWrite(lmotorb,LOW); digitalWrite(rmotorb,LOW); } else if((sensor2==LOW)&&(sensor3==HIGH)&&(sensor4==LOW))

{ digitalWrite(lmotorf,HIGH); digitalWrite(rmotorf,HIGH); digitalWrite(lmotorb,LOW); digitalWrite(rmotorb,LOW); } else if((sensor1==HIGH)&&(sensor5==LOW)&&(sensor2==LOW)&&(sensor3==HIGH)&&(sensor4==LOW))//1 LEFT

{ digitalWrite(lmotorf,HIGH); digitalWrite(rmotorf,LOW); digitalWrite(lmotorb,LOW); digitalWrite(rmotorb,LOW); }

else if((sensor1==LOW)&&(sensor5==HIGH)&&(sensor2==LOW)&&(sensor3==HIGH)&&(sensor4==HIGH))//1 LEFT

{ digitalWrite(lmotorf,HIGH); digitalWrite(rmotorf,LOW); digitalWrite(lmotorb,LOW); digitalWrite(rmotorb,LOW); } else if((sensor1==HIGH)&&(sensor5==LOW)&&(sensor2==LOW)&&(sensor3==LOW)&&(sensor4==LOW))//1 LEFT

{ digitalWrite(lmotorf,HIGH); digitalWrite(rmotorf,LOW); digitalWrite(lmotorb,LOW); digitalWrite(rmotorb,LOW); }

else if((sensor1==LOW)&&(sensor5==HIGH)&&(sensor2==HIGH)&&(sensor3==HIGH)&&(sensor4==HIGH))//NULL

{ digitalWrite(lmotorf,HIGH); digitalWrite(rmotorf,LOW); digitalWrite(lmotorb,LOW); digitalWrite(rmotorb,LOW); } else if((sensor2==LOW)&&(sensor3==LOW)&&(sensor4==HIGH))//1 LEFT

{ digitalWrite(lmotorf,HIGH); digitalWrite(rmotorf,LOW); digitalWrite(lmotorb,LOW); digitalWrite(rmotorb,LOW); } else if((sensor2==LOW)&&(sensor3==HIGH)&&(sensor4==HIGH))//1 LEFT

{ digitalWrite(lmotorf,HIGH); digitalWrite(rmotorf,LOW); digitalWrite(lmotorb,LOW); digitalWrite(rmotorb,LOW); }

else if((sensor2==HIGH)&&(sensor3==LOW)&&(sensor4==LOW))//FOR RIGHT

{ digitalWrite(lmotorf,LOW); digitalWrite(rmotorf,HIGH); digitalWrite(lmotorb,LOW); digitalWrite(rmotorb,LOW); }

else if((sensor2==HIGH)&&(sensor3==HIGH)&&(sensor4==LOW))//FOR RIGHT

{ digitalWrite(lmotorf,LOW); digitalWrite(rmotorf,HIGH); digitalWrite(lmotorb,LOW); digitalWrite(rmotorb,LOW); } else if((sensor1==HIGH)&&(sensor5==LOW)&&(sensor2==HIGH)&&(sensor3==HIGH)&&(sensor4==HIGH))//1 LEFT { digitalWrite(lmotorf,LOW); digitalWrite(rmotorf,HIGH); digitalWrite(lmotorb,LOW); digitalWrite(rmotorb,LOW); } else if((sensor1==HIGH)&&(sensor5==LOW)&&(sensor2==HIGH)&&(sensor3==HIGH)&&(sensor4==LOW))//1 LEFT { digitalWrite(lmotorf,LOW); digitalWrite(rmotorf,HIGH); digitalWrite(lmotorb,LOW); digitalWrite(rmotorb,LOW); }

else if((sensor1==LOW)&&(sensor5==HIGH)&&(sensor2==LOW)&&(sensor3==HIGH)&&(sensor4==LOW)) { digitalWrite(lmotorf,LOW); digitalWrite(rmotorf,HIGH); digitalWrite(lmotorb,LOW); digitalWrite(rmotorb,LOW); } else if((sensor1==HIGH)&&(sensor5==LOW)&&(sensor2==HIGH)&&(sensor3==HIGH)&&(sensor4==HIGH)) { digitalWrite(lmotorf,LOW); digitalWrite(rmotorf,HIGH); digitalWrite(lmotorb,LOW); digitalWrite(rmotorb,LOW); }

else if((sensor2==HIGH)&&(sensor3==HIGH)&&(sensor4==HIGH))//FOR RIGHT { digitalWrite(lmotorf,HIGH); digitalWrite(rmotorf,HIGH); digitalWrite(lmotorb,LOW); digitalWrite(rmotorb,LOW); } else { digitalWrite(lmotorf,LOW); digitalWrite(rmotorf,LOW); digitalWrite(lmotorb,LOW); digitalWrite(rmotorb,LOW); }

}

I hope this was helpful !

All the best and Have fun :)

18 Comments

I want to put another 2 sensor at the edge of the front car.
Can you explain the code?

Is it true that if the sensor on the edge of the car make it more smooth on the acute angle corner?
I followed the instructions and it work well. Thanks.
Anyway it is work well in black line with width 3.5 cm buat I won't work at line 2cm.
Any idea?
Thanks
Already find out.
I adjust the position of the sensor and the front wheel.
It good to go, but it shake alittle. But more stable at corner.
Thanks
The connections isn't clear?
and, may I ask why didin't you add the IR in front for obstacles avoiding?
your code was very helpfull, but you could've address the sensors in a more comprehensive way so we all know wich is wich.
But, thanks for the effort you did anyway

hey can i use a motor shield insted of L293D ( i have both anyway )

Can i chage the driver motor L293D with L298N?

yes you can use L298N instead of L293D....but make sure your connections must be according to its datasheet

all the best :)

https://www.instructables.com/id/Face-Detectionrecognition/

and also your coding logic ........

Nice Project!

can u pls give the Indian shopping link to the ir sensor?Or from where did u buy it?
thanks hrithikbansal70
u can get the 5 channel ir sensor module from :
http://www.ebay.com/itm/Five-5-Channel-Tracking-Sensor-Module-Board-Trace-Module-Infrared-Detection-New-/272109624665

all the best :)
Hi.1.my motor driver (l298n) have ENA and ENB pins.where will i connect them? 2.i have same ir sensor set : clp and near sensors are empty in yours too is it correct? 3. I understoog that in your program ina, inb,inc,ind pins connected to arduino digital 4,5,6,7 is it true? Thank u.
Ena nd enb pins for speed control but in this project there is no need of them so u can short it wid +5v
2.all the connection nd code are perfect don't worry about it
thnks
Hi.1.my motor driver (l298n) have ENA and ENB pins.where will i connect them? 2.i have same ir sensor set : clp and near sensors are empty in yours too is it correct? 3. I understoog that in your program ina, inb,inc,ind pins connected to arduino digital 4,5,6,7 is it true? Thank u.

cool design and idea nd thnxs for ur code its awesome