Boe Bot/Arduino Line Following Robot




This is a fairly straightforward guide of how to build a line following robot. it uses lights, light dependent resistors (LDRs), an arduino, and a boe bot chassis (any robot chassis with 2 continuous rotation servos will work). it reads the sensors and turns based on the amount of light reflected form the surface below it. the sensors could also be used to detect edges.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Build the Sensor

you will have to build the sensor to the included schematic

Step 2: Mount the Arduino, and Connect the Wires

i used an arduino mega, but you could use an uno. mounting will vary based on arduino and chassis. you could also use an arduino board of education from parallax.

Step 3: Program It!

// Project 30 - Line Following Robot
#include <Servo.h>
#define lights 7
int LDR1, LDR2, LDR3; // sensor values

// calibration offsets
int leftOffset = 0, rightOffset = 0, centre = 0;

// starting speed and rotation offset
int startSpeed = 125, rotate = 30;
// sensor threshold
int threshhold = 5;
// initial speeds of left and right motors
int left = startSpeed, right = startSpeed;
Servo lefts;
Servo rights;

// Sensor calibration routine
void calibrate() {

  for (int x=0; x<10; x++) { // run this 10 times to obtain average
  digitalWrite(lights, HIGH); // lights on
  LDR1 = analogRead(0); // read the 3 sensors
  LDR2 = analogRead(1);
  LDR3 = analogRead(2);
  leftOffset = leftOffset + LDR1; // add value of left sensor to total
  centre = centre + LDR2; // add value of centre sensor to total
  rightOffset = rightOffset + LDR3; // add value of right sensor to total
  digitalWrite(lights, LOW); // lights off
  // obtain average for each sensor
  leftOffset = leftOffset / 10;
  rightOffset = rightOffset / 10;
  centre = centre /10; 
  // calculate offsets for left and right sensors
  leftOffset = centre - leftOffset;
  rightOffset = centre - rightOffset;

void setup()

    // set the motor pins to outputs
    pinMode(lights, OUTPUT); // lights

    // calibrate the sensors
    digitalWrite(lights, HIGH); // lights on
    // set motor direction to forward
    // set speed of both motors

void loop() {
  // make both motors same speed
  left = startSpeed;
  right = startSpeed;

  // read the sensors and add the offsets
  LDR1 = analogRead(0) + leftOffset;
  LDR2 = analogRead(1);
  LDR3 = analogRead(2) + rightOffset;
  // if LDR1 is greater than the centre sensor + threshold turn right
  if (LDR1 > (LDR2+threshhold)) {
    rotate = LDR2 - LDR3;
    left = startSpeed + rotate;
    right = startSpeed - rotate;
  // if LDR3 is greater than the centre sensor + threshold turn left
  else if (LDR3 > (LDR2+threshhold)) {
    rotate = LDR2 - LDR1;
    left = startSpeed - rotate;
    right = startSpeed + rotate;
  else {
    left = startSpeed;
    right = startSpeed;
    // send the speed values to the motors
    rights.write(180 - right);

Step 4: Finish It Off

fire it up and send it out on a line (i suggest a line 3/4 to 1 inch wide)
you may have to tweak it, but hopefully not much 

ShopBot Challenge

Participated in the
ShopBot Challenge

Arduino Challenge

Participated in the
Arduino Challenge

Be the First to Share


    • Assistive Tech Contest

      Assistive Tech Contest
    • Reuse Contest

      Reuse Contest
    • Made with Math Contest

      Made with Math Contest

    5 Discussions


    6 years ago on Step 3

    can you post a video of this working????


    6 years ago on Introduction

    May i have a schematic diagram? i feel blur about the "light"

    Robot Lover

    7 years ago on Introduction

    Looks like a fun project! Line following robots are always cool. Anyway, great project!