Make:it Line-Following Robot

Today I got the chance to play with a Make:it Line-Following Robot.   This robot is an Arduino based robot using 2 DC motors.   I wanted to try and understand how a microcontroller code related to real world actions of the robot, and how all of the different components came together to work as one.

The Make:it Line-Following Robot is shown below.   It is a machine that follows a line, either a black line on white surface or vise-versa.   This line-following robot was purchased as a kit, however, the Arduino Uno was purchased separately.   A printed circuit board (PCB) which had already been assembled was included in the kit.

This line-following robot uses infrared (IR) sensors to guide them. If the optical sensor is over a white reflective surface, the IR light from the sensor is reflected and received.   If the sensor is over a black surface, the IR light is absorbed and the sensor does not detect it.

Make:it -Line-following-robot

Optical Sensors

An optical sensor is a device that converts light into electrical signals.   The amount of light that gets converted is proportional to the electrical signal strength.   The optical sensor has the ability to measure the changes from one or more light beams.   In the line following robot optical sensors are used to guide the robot’s path. Using a white background with a black strip the optical sensors can recognize the black line and follow it.   Since the contract between the black line and the white background is so big the optical sensors has no problem determining the difference between the two.   The optical sensors on the line following robot are like a human’s eyes.

Driver Board

The line-following robot includes a printed circuit board (PCB), or driver board.   The board is made from glass reinforced plastic copper tracks in place of wires.   Components are fixed in a position by drilling holes through the board, locating components and then soldering them in place.   The copper tracks link the components together forming a circuit.



Arduino UNO

An Arduino is a microcontroller on a circuit board which makes it easy to receive inputs and drive outputs.   It is used for building electronics projects.   Arduino consists of both a physical programmable circuit board and a piece of software that is used to write and upload computer code to the Arduino.   The best part about the Arduino software is that it’s free.

For this project, I used an Arduino Uno (R3).   The first step was to download the Arduino software package for Windows operating system.   It has 14 digital input/output pins, 6 analog inputs, a USB connection, a power jack, and a reset button.   It contains everything needed to support the microcontroller.   It’s very easy to use, just connect it to a computer with a USB cable.   After purchasing the Arduino, the first step was to download the Arduino software package.  The arduino is coded in C++.


DC motor

The part of the robot actuation system that allows it to move is called the drivetrain.   The heart of the drivetrain is the motor.   The robot consisted of two brushed direct current (DC) motors.   DC motor are very common and have been used for a long time.   They are reliable, sturdy and relatively powerful.   The direct current is provided from eight AA batteries that power the motors.


A common way of controlling the speed of the DC motors is through a technique called Pulse-Width Modulation (PWM).   PWM is basically a way of changing the “on” time percentage of an electrical signal in order to control the amount of current going to the motor.   PWM turns the motor on and off very quickly, delivering small jolts of power.   A greater percentage of “on” time means the motor spins faster.   PWM helps slow the motor down while keeping its output torque relatively high.

Motors have torque-speed curves.   For a fixed input voltage from a battery, such as the 12 volts for this robot, the motor speed slows down as it is loaded.   With no load on the shaft the motor runs the fastest possible speed for that voltage.   Fully loaded means the shaft is not allowed to move. In this case the speed is zero and the motor is producing what’s known as its stall torque.  This is the maximum possible torque.   An example of the stall torque is if you squeeze down on the shaft of the motor with your fingers while it is spinning.   As you squeeze harder, the load is increased and the motor speed will drop.   If you squeeze hard enough and you stop the shaft from turning, this is what stalls the motor.



Source Code

// * File Name         : linefollow
// * Author             : RadioShack Corporation
// * Version           : V1.0
// * Date               : 2014/01/16
// * Description       : Optical sensors send feedback to PCB
// *                     to make the robot follow a black line on a white background.
// ********************************************************************************
//   This program is free software: you can redistribute it and/or modify
//   it under the terms of the GNU General Public License as published by
//   the Free Software Foundation, either version 3 of the License, or
//   (at your option) any later version.
//   This program is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   GNU General Public License for more details.
//   You should have received a copy of the GNU General Public License
//   along with this program. If not, see <>.
// ********************************************************************************

#include <MakeItRobotics.h>//include library
MakeItRobotics line_following;//declare object
// **************************************************************************
// *                           Power Up Initial
// **************************************************************************
void setup()
Serial.begin(10420);                     //tell the Arduino to communicate with Make: it PCB
delay(500);                              //delay 500ms
line_following.line_following_setup();   //initialize the status of line following robot
line_following.all_stop();               //all motors stop
// **************************************************************************
// *                           Main Loop
// **************************************************************************
void loop()
static int sensor_in;                 //variable to store the value of read_optical function feedback
static int sensorValue1 = 0;           //variable to store optical1 status
static int sensorValue2 = 0;           //variable to store optical2 status
static int sensorCnt = 0;             //variable to count for trigger which optical
static long sensorTimer1 = millis();   //last triggered time
static long sensorTimer2 = millis();   //now time
static int action1 = 0;               //now action
static int action2 = 0;               //last action
// Trigger Left/Right optical every 15 milliseconds
sensorTimer2 = millis();                 //read now time
if (sensorTimer2 – sensorTimer1 > 15)   //if now time minus last triggered time is greater than 15ms, then trigger another optical
sensorTimer1 = sensorTimer2;           //last triggered time = now time
-> trigger optical1 -> greater than 15ms -> trigger optical2 -> greater than 15ms ->|
if (sensorCnt == 0)
else if (sensorCnt == 1)
if (sensorCnt == 2)
sensorCnt = 0;
// Read Left/Right optical status
Reads the value from optical1(Right side) or optical2(Left side)
0x000 optical1 black
0x0ff optical1 white
0x100 optical1 white
0x1ff optical1 black
0x2XX not ready; don’t use this value
if((sensor_in & 0xf00)==0)
sensorValue1=sensor_in & 0xff;
else if((sensor_in & 0xf00)>>8==1)
sensorValue2=sensor_in & 0xff;
if (sensorValue1 == 0x00)
action1 =action1 & 0xfe;
if (sensorValue1 == 0xFF)
action1 = action1 | 0x01;
if (sensorValue2 == 0x00)
action1 = action1 | 0x02;
if (sensorValue2 == 0xFF)
action1 = action1 & 0xfd;
left       right
0x00   black       black
0x01   black       white
0x02   white       black
0x03   white       white
Make Robot Move
if action1 is not equal to action2, then change motor status
if action1 is equal to action2, then do nothing
if(action1 != action2)
if (action1 == 3 )
if (action1 == 1)
if (action1 == 2)
if (action1 == 0)

Author: Claude