
This is line follower robot using Arduino, which is a very common Arduino base Project. The robot will use two infrared proximity sensors to detect the line and on the basis of input received from the sensors, the Arduino will direct the motors to move with the help of a motor shield (L293D).
Step 1: The Working Theory
So there will be infrared proximity sensors placed on either side at the front of the robot. There are four possible sensor outcomes:-

Case 1:-
In this case, both the sensors don’t detect the line. Both the motors rotate forward. As a result, the car moves forward.

Case 2:-
In this case, only the left sensor detects the line which means that the car requires to turn in the left direction. The left motor rotates backward and the right motor rotates forward. As a result, the car turns left.

Case 3:-
In this case, only the right sensor detects the line which means that the car requires to turn in the right direction. The left motor rotates forward and the right motor rotates backward. As a result, the car turns right.

Case 4:-
In this case, both the sensors detect the line. This means that the end has come. Both the motors stop rotating. As a result, the car stops.
That is the working structure of our robot…
Step 2: Parts Required :
The parts required to build the robot are as follows:
- Chassis (including motors and wheels )
- Arduino Uno R3-1pcs
- L293D Motor Shield-1pcs
- IR Proximity Sensors (pair)
- Jumper Wires
- Switch
- 4AA Battery Holder
Tools required:-
Step 3: Assemble the Chassis


Now, assemble your robot body. Everyone may have a different chassis. So assemble your chassis accordingly. Most of the chassis come with an instruction manual and even mine came with it so have a look at it and build your chassis accordingly. Then, attach the components to the chassis. Arduino, with the motor shield attached to it and also the battery holder must be fixed on the chassis.
Also, attach the proximity sensors at the front on either side, facing down. Make sure that they are attached at the corners…
Attach the switch too…
Solder wires to the motors and also switch and keep ready…Add TipAsk QuestionCommentDownload
Step 4: Main Connections

Now do the connections as per the diagram above…
Left Sensor>>Arduino:-
- Vcc>>5v
- Gnd>>Gnd
- Out>>A4
Right Sensor>>Arduino:-
- Vcc>>5v
- Gnd>>Gnd
- Out>>A5
Connect the motors to the motor shield and plug the motor shield onto the Arduino board. Connect the battery holder to the shield through a switch. That’s it for the connections, let’s move on to the next step…Add TipAsk QuestionCommentDownload
Step 5: Arduino Code Uploading:

Now its time for the main thing- coding our robot..
Upload the below arduino Code in to the Arduino Uno R3:
#include <AFMotor.h>
//defining pins and variables
#define lefts A4
#define rights A5
//defining motors
AF_DCMotor motor1(4, MOTOR12_8KHZ);
AF_DCMotor motor2(3, MOTOR12_8KHZ);
/*
AF_DCMotor motor1(3, MOTOR12_8KHZ);
AF_DCMotor motor2(4, MOTOR12_8KHZ);
*/
void setup() {
//setting the speed of motors
motor1.setSpeed(200);
motor2.setSpeed(200);
//declaring pin types
pinMode(lefts,INPUT);
pinMode(rights,INPUT);
//begin serial communication
Serial.begin(9600);
}
void loop(){
//printing values of the sensors to the serial monitor
Serial.println(analogRead(lefts));
Serial.println(analogRead(rights));
//line detected by both
if(analogRead(lefts)<=400 && analogRead(rights)<=400){
//stop
motor1.run(RELEASE);
motor2.run(RELEASE);
}
//line detected by left sensor
else if(analogRead(lefts)<=400 && !analogRead(rights)<=400){
//turn left
motor1.run(BACKWARD);
motor2.run(FORWARD);
/*
motor1.run(RELEASE);
motor2.run(FORWARD);
*/
}
//line detected by right sensor
else if(!analogRead(lefts)<=400 && analogRead(rights)<=400){
//turn right
motor1.run(FORWARD);
motor2.run(BACKWARD);
/*
motor1.run(FORWARD);
motor2.run(RELEASE);
*/
}
//line detected by none
else if(!analogRead(lefts)<=400 && !analogRead(rights)<=400){
//stop
motor1.run(FORWARD);
motor2.run(FORWARD);
/*
motor1.run(BACKWARD);
motor2.run(BACKWARD);
*/
}
}
this post collected from instructables.com