Arduino Based Basic Line Following Robot Car 4

In this blog, we will explore how to make an Arduino based basic line follower robot utilizing Arduino Line Following Robot Kit V2.0

First, let us have a look at the kit contents:

BO Motors
Castor Wheel
IR Proximity Sensors
Arduino UNO R3 programmed
Motor Driver Shield soldered analog pins
Jumper Wires F-F
Nut, Bolt, Spacer & motor clamps
BO Wheels
Battery Holder
Cap and switch
Screw Driver
Cable Ties
USB A-B Programming Cable

Arduino UNO R3

Arduino UNO R3 board is used as the controller, which takes digital input from IR Proximity sensors and drive the two DC motors through L293D Motor Driver Shield.

IR Proximity Sensor

IR Proximity sensors comprise of IR LED and photodiode pair with on board LM393 comparator. They give digital output. There is an onboard potentiometer to calibrate the digital o/p. On board o/p LED helps in calibration. These sensors are quite sensitive to ambient light hence calibration is recommended every time ambient light conditions change. We will see later on how to do black-white line calibration.

L293D Arduino Shield

Arduino Motor Driver Shield comprises of L293D motor driver Ics which enable us to drive four DC motors or 2 Stepper Motors and 2 Servo motors simultaneously through Arduino.

It has screw connector headers for connecting 4 DC motors M1, M2, M3 & M4 or 2 nos 5-wires unipolar stepper motors. There are berg strip male connectors for connecting 2 servo motors Sero1 & Servo2 for 3 pin servo interface Vcc, GND & SIG. Vcc is +5V. Screw connection headers are given for connecting external DC power supply for motors and Arduino.

Always keep the jumper inserted to power Arduino through Motor Driver Shield.

On board voltage regulator provides 5V logic voltage output for Arduino and other components requiring the same. This motor driver shield is designed for Arduino UNO board and makes available all analog pin on Arduino with power pins as male berg connectors. Peripherals requiring +5V can be easily powered by the battery through Shield. Since other pins are already utilized in the shield we will be using these analog and power pins to connect our sensors to Arduino.

Assembling The Kit: a video will demonstrate it.

Proximity Sensor Calibration

Let us now connect our Arduino to PC via USB cable provided. Make the sensors face the surface with line to be followed. Calibrate the sensor by rotating potentiometer such that on board out put LED lights on white surface and goes OFF on black surface. The o/p should be crisp and quick during the transition from black to white or vice versa as indicated by LED. Fine-tune your calibration.


Once satisfied upload the following sketch to Arduino. Please note that the Arduino which comes with Mazatron’s Line Follower Smart Car Kit is pre-programmed with the following sketch. It makes our robot follow black line on white background. It can be modified to follow white line on black background(please refer comments).

#include <AFMotor.h>

AF_DCMotor motor1(3);       //left motor connected to M3
AF_DCMotor motor2(4);       //right motor connected to M4

int left_sens_val;         //variable to store left IR sensor value
int right_sens_val;        //variable to store right IR sensor value

void setup() {
  motor1.setSpeed(150);   //motor speed range from 0-255
  motor2.setSpeed(150);;    //motor stop;

void loop() {

  left_sens_val = analogRead(A0);     //left sensor connected to analog pin A0
  right_sens_val = analogRead(A1);    //right sensor connected to analog pin A1
  if(left_sens_val > 500 && right_sens_val < 500){       //reverse the <,> signs for white line on black background;        ;
  else if(left_sens_val < 500 && right_sens_val > 500){   //reverse the <,> signs for white line on black background;;
  else if(left_sens_val < 500 && right_sens_val < 500){    //reverse the <,> signs for white line on black background;;
  else if(left_sens_val > 500 && right_sens_val > 500){    //reverse the <,> signs for white line on black background;;


If all goes well the robot will start following black line on a white background.

Please note that there is a battery holder provided with the kit to run bot on four 1.5V Dry Cell Batteries but make sure to use High Power Batteries.

If using other batteries then you might have to play with the motor speed and delay values.

motor1.setSpeed(150);   //motor speed range from 0-255
If you hear only motor vibration sound and no movement or if the bot is moving very slow, kindly use higher voltage batteries or increase the speed. If you find that the bot is overshooting the line then decrease delay.

Fine tune the IR proximity sensors every time the lighting conditions change.

Note: If a motor is found to be moving in reverse direction of as intended, swap the wires for that particular motor connected at connectors M3 or M4.

Do let us know any of any queries or clarifications in the comments.


  1. Hey hi guys I m frist time doing my own robot car so plz help me to get the code of line following robot and the website is awesome and the things are in low price I hope things also of best quality and thq and plz help to get code and I didn’t have laptop

  2. Nice to know that you blog. It will be quite helpful to make some projects for fun 😄😊

  3. You have blog nice.

    1. Thanks for your appreciation.

Leave a Reply