Site Overlay

How to construct an autonomous Robot capable of following a 10m white line.

Hits: 11

This acts as a formal presentation of the step by step techniques used to build this very unique Robot machine. This includes the sophisticated detail of Circuitry, Programming  and elementary designs. The designs in this document explain explicitly the efforts put together to construct the robot.


  • To design and construct an autonomous Robot that is capable of following a 10m white line.
  • To be able to work formally as a company, given the task of constructing a robot machine for the purpose specified.
  • To have a feel and understanding of the proprietorship within a much larger organisation as ones met in real life, compared to the robotics group. This builds up since the way of running big companies and businesses is based on the same organisation principles.


  • The Robot should be capable of carrying an egg while undertaking its journey, and should be fast enough to enter a race competition. 
  • To finish the race without dropping the egg in the earliest time possible.
  • To ensure that the robot maintains its track and not stray.

The Mitsubishi board (M16C/62)

There are several facts to consider when using the M16C/62 chip, most of which turn out to be advantages and hence it’s convenience in use.

  • M16C Reduces Total System Cost
  • Program ROM (Read Only Memory) Size Reduced
  • Highly Functional Tools Reduce Development Time
  • ROM Code Correction Function Fixes Bugs after Masking
  • Reduces EMS Design Cost (protected up to 20KV discharge)
  • Reduces EMI Design Cost (20dB reduction in radiated noise)
  • Use of Small Battery for Back-up Due to Ultra Low-power Dissipation
  • High On-chip Integration Reduces System Costs
  • High-speed Operation with Low-price/Low-speed Memory
  • 8 Channels of 10 bits Analogue to Digital Converter, 2 Channels of 8 bits Digital to 256KB of ROM, 4KB of RAM
  • Analogue Converter.
  • Comes with a Watchdog Timer.
  • 87 Programmable Input and Output Lines
  • Processor Speed: 16MHz
  • Instruction Set has been optimised for C language programming.
  • Supply Voltage: 4V to 5.5V
  • 3 channels of UART (Universal Asynchronous Receiver and Transmitter).
  • 20 Internal and 5 External Interrupt Sources, 4 Software Interrupt Sources.

The design of this Robot has been implemented in a way that it will take the Mitsubishi Programming kit on board. The Robot therefore has been structured in order to stack this board on top of the metal chassis as shown below.

The monitor program and a bit on programming the board

The Mitsubishi board is initially programmed to run a testing program. This is a counting program that  lights the seven segment display and runs a program that counts from 00 to 99. This program is installed by the manufacturers of the Mitsubishi board  as a test to proper functioning of the board. At this stage, the board is useless to us until a Monitor  program software has been installed. This is done by moving a jumper on the board and using the software program IAR, to install the monitor program. The details of this process will not be covered here. The monitor Program functions as an ‘OK’ program that enables information to be exchanged between the computer and the M16C chip.

Problems in software installation encountered while using this board

There are problems in compilation and downloading of the programs as it may normally happen in any programming laboratory. One of the problems you may encounter is that the program does not compile in the first place. The course of this the monitor program is not been properly installed.

Efficiency of the board ( considering it has to be powered to retain its memory)

The Mitsubishi Board is efficient in all programming cases, apart from the fact that it has to stay powered in order to retain its memory. Once  programmed, the power must not be cut from the chip. If this happens, the programmer has to reprogram the chip in order to continue using it.  This has been done deliberately by the manufactures of Mitsubishi M16C/62, in order to protect it from piracy and from  people creating brilliant programs on it and selling it. This would of course terminate the Mitsubishi industrial market. 

Circuit diagram showing the ports to use for motors and sensors

Schematic Diagram showing Port Connections to the motors , the motor circuit (to be discussed later)is omitted here. The sensors are connected in the same way, but on port 10, pins 2 and 3


Testing is efficiently done by checking that the test counter program is running when the Mitsubishi M16C board is powered.

Design and positioning of the Plastic Spoon Holder

The purpose of the groove is to ensure that the spoon sits nicely in the centre. We drill a hole in the middle of the plastic and on the spoon, this is to tighten the spoon make sure that it sits on the centre firmly.  A metal piece is place across the spoon for additional re-enforcement so that spoon will not move or jerk with huge movement.

Motors and The Motor Circuit

Why use Stepper Motors

In this project, we require a form of “engine” to drive the wheels of our robot. It has to be capable of responding to the Mitsubishi M16C’s commands and provide enough drive to move the whole chassis of the robot by driving the wheels. We have used the stepper motor to achieve this purpose.

Characteristics of a stepper motor

The ability to ‘step’ a little bit at a time through proper control of the winding coils.

Holding torque: allows the stepper motor to hold its position firmly when not turning. This is useful for applications that require the stepper to start and stop, while retaining the force acting on the motor, so that applications do not require extra braking.

Contains energizing coils inside. Need to energize the winding coils in a correct sequence before the motor’s shaft will rotate.

A Stepper Motor Control Circuit Diagram  

The following diagram Figure 1.7a, shows the circuit used in our project to control the stepper motor. The use of 8 diodes in the circuit is to prevent any current or voltage surges when the stepper motor coil is energised. 8 control lines are used to connect the individual transistors to the Mitsubishi M16C micro-controller via 8 1KW resistors. The outputs (i.e. the collector pin of each transistor) are connected to the motor coils through the different colours of cables (brown, orange, red and yellow).

Choice of transistor for the circuit: TIP110

Choice of diode for the circuit: 1N4001

In short summary; The circuit has transistors to buffer the Mitsubishi Chip, since many stepper motors run off 12V and take a significant current. The fly back diodes on the other hand are used to suppress the voltage spike when the coil is turned off.

A detailed Stepper Motor Circuit showing connections to the Mitsubishi board

Powering the Motor Circuit (voltage etc)

Basically, this motor control circuit will be using 12V power supply as the single power source. The control signals from the micro-controller will be in the form of +5V (logic ‘1’) and 0V (logic ‘0’).

Planning of circuit onto the PCB

In the planning stage of the circuit onto the copper board, our objective is to optimise the available space to accommodate all the components. The initial plan is to connect the cables from the motors straight to the output (i.e. collector) of every individual transistor. After our initial planning, we found out that the cables are very messy. The solution we are using is to introduce PCB sockets to the circuit board. In the board, we use a 10-way and a 5-way socket for the cables from the motors and a 10-way socket for the inputs from the Mitsubishi M16C. The cables and the wires are then connected into the PCB plugs for connection to the sockets. The final planning of our circuit is shown in the following diagram.

Planning of circuit onto the PCB

Note 1: The red lines in the diagram indicate a cut in the long tracks. This is to prevent any short-circuit in the PCB.

Note 2:  The dimensions of the PCB are 60mm by 110mm.

Photograph of the implemented PCB ( Printed Circuit Board)

Sensors and  The Sensor Circuit

Use OPTO Switch Reflective Sensors for  the  robot . The following is a list of the main features of  OPTO sensor.

  • Photo-transistor output
  • Unfocused for sensing diffuse surface
  • Low cost plastic housing
  • Enhanced signal to noise ration
  • Reduced ambient light sensitivity
Type of Sensors Used

The OPTO SWITCH REFLECTIVE Sensor consists of an infrared emitting diode and an NPN silicon photo-transistor mounted “side-by-side” on parallel axes in a black opaque plastic housing . Both the emitting diode and photo-transistor are encapsulated in a filtering epoxy to further reduce ambient light noise. The photo-transistor responds to radiation from the emitter only when a reflective object passes within its field of view. The photo-transistor has enhanced low current roll off to improve the contrast ratio and immunity to background irradiance.

Advantages of the  OPTO Switch Reflective Sensor

  • LED and Infra-red sensor(a Photo transistor) circuitry are combined together into one component. This will help to save space on the matrix board. Thus making the board small.
  • Don’t have difficult aligning the LED and Infra-red sensor since they are combine into one component. (during testing in order to get the best result)

The only drawback to this sensor is that the sensing range is too short (about 3mm). Therefore, we have to position our sensor very close to the ground.

Reason for using two Sensors

The Initial design was to be implemented using at least two sensors. According to our management criteria, it was possible to order six sensors. The extra four would act as spare ones just in case if the ones being used are damaged. This is done to reduce the amount of time wasted in ordering and waiting for the components to be delivered.

Two sensors would  be placed off the line and two on the line, each pair detecting if the robot is off the track  line or on  the track line respectively. The sensors outside the line will watch on  the white track  line and the ones on the line would beware of the dark area outside the line. The concept behind this is to improve the robots performance, in enabling it to readjust itself on to the white line at all time and not drive in a left-right-left  wavy motion after a turn.  This  means that the sensors will need to be accurately adjusted on and off the line.

Finally the idea of just using two sensors proved promising if mounted in the right positions and with a high degree of accuracy. 

The sensors were hence forth mounted on the outer edges of the line, this being due to the fact that  there were few risks of having them on the inner edges when it came to a 90º turn. 

Sensor Circuitry

A photograph of one Sensor Circuit as implemented

The spool holding the sensors is mounted in front of the robot .  The initial design was to mount the sensors at the centre, as close to the wheels as possible, so that the robot could turn easily. The sensor range though is so small so this would not be the best idea, but still this idea can be put into testing in the future. From the geometry of the robot, the easiest way to establish that optimum performance of the sensor is  to mount them at the front using a spool.

The Spool and the Sensors attached

The Left and Right Sensor were therefore positioned at the front bottom of the robot (onto the spool). They are placed about 3mm from the ground on the edges of the white tape. 

They are position at the edge of the left and right hand side of the white tape. In this way, it will keep the robot in line with the white track. 

The outline of our robot is relatively simple as it was built with a piece metal as base of dimension 170mm x 110mm. The stepper motors are placed at the rear of base piece and a movable third wheel (Ball Bearing)  in the middle front. We replaced our third rotary wheel with ball bearings as the latter is move versatile being smooth and ability to move in all direction without difficulties. 

To ensure that the robot is stable when moving at high speed while carrying an egg, The base must be as close to the ground as possible. The wheels provided were too small to suit the design so a new slightly bigger wheel had to be purchased. A lower base also ensure that the infra-red sensors are closer to the white tape. To improve their sensitivity.

The wheel
Battery Pack Holder

The entire robot must be autonomous and thus it has to have a battery. A different system could be used where the robot does not carry the battery on a battery pack. This would mean that the power source will have to be located somewhere else and have flexible extension cables conveying the power to the robot. We decide to use light but powerful batteries that are fixed to the robot via a battery pack.

The battery must be long lasting as discussed in the motor section, the motors take an enormous amount of current, hence the use of the ‘flyback’ diodes on the motor circuit.  

The minimum total voltage of the source as  calculated is 12V. The distribution of this voltage is as discussed below;

  • The Mitsubishi board (+5V)
  • The Sensors and Sensor Circuit total (10V)
  • The Motors and Motor Circuit (12V)

Potential dividers would be used whenever a voltage needs to be divided into smaller voltages. We are still keeping this in mind, and potential dividers may come in handy at a later stage of the system development.

Type of software

The software used is C Programming in  an IAR platform program, that is a basic toolkit for basic Micro-controllers and Microprocessor programming. A sample of the code being used in this program can be found on the Appendices on the last few pages of this document.

Pseudo code of the software

A Pseudo code in the programming language is a simple English statement  written to explain what a program does. The Pseudo code for the software used in this Project is as follows:

  • Initialize The program, noting if the program is already running.
  • Check the sensors can detect any readings (the track)
  • Take the readings and if the voltage received by the sensors is of a specified quantity, then send the corresponding instructions to the motors.
  • Repeat these instructions until there is no more reading or the power is cut off.

For the testing results to be positive., motors must be able to turn and the sensors reading the analogue signals from the track  must be ‘listened ‘to by the chip. This is basically the communication path in that the analogue signals as detected by the sensors are sent to the chip, the chip then sends the corresponding out put signals to the motors to make them turn.

Integrating the Mechanical, Software and Electronics

Putting it all Together !  The entire system is integrated using System integrators. These system integrators could  either be of the form of software or hardware. The only condition is that a system integrator must be capable of interlinking two or more subsystems, to build an entire system. For example in this project the subsystems that need to be integrated are;

  • The software and
  • The hardware

The software is further subdivided into Functions in C programming, such as Time delay function, Drive Motors function and Read Sensors Functions. These functions can be labelled as anything but for simplicity here the functions do just what they are called. For example the function Drive Motors, starts to drive the motors as soon as it is called within the main software program. The Program used in this project may or may not contain the functions as named above and may contain other functions not specified here. These are just for illustration purposes.

To integrate these bits of software, the programmer builds a main program that combines all the functions within the program in a skilful way. Hence creating a whole entire software system. The software is then stored in the Mitsubishi chip board hardware. The Mitsubishi board here acts as a link between the robot and the software, hence an integrator.

Other hardware integrators used in these project are cables, which help connect all the hardware together. These are crucial connectors worth discussing about apart from the normal screws used to hold the system together. The pictures below show the cables used in this project and explain how they are linked.

Showing the connection cable for connecting the motors to the Mitsubishi Board, The Sensor cable has only two lines and are connected in the same way

Testing Procedure on the Sensors Circuitry

The sensor was tested using plain white paper. The distance away from the reflective surface is of critical concern so a test plan had to be drawn. This enables the determination of the sensors range limits of expansion for best results. Limits of expansion here is rather the field of view for the sensors.

Test Procedure

  • Input +5V to both resistors on pin 3 and 1 of the sensors and GND to pin 4 and 2 of the sensors of the sensors circuitry.
  • Use a probe to check the output waveform on pin 2 of the sensors just before the resistor. Observe the voltage waveform on the oscilloscope. It be should in the high state (+5V) since it is not sensing any reflective object.
Sensor Testing
  • If the correct voltage waveform is obtained, proceed to put a white reflective object in front of the sensors. Observe the voltage waveform on the oscilloscope. The voltage level should decrease to around 0V.
  • Change distance between object and sensor and observe new output. Record findings

Result table for sensor testing

Analysis of result

Graphical illustration of results obtained


As the graph show when infrared light was detected the output was approximately 2 volts and in the absence of infrared light, the output was 5 volts. The conclusion drawn from the testing for the sensor indicated that the sensor was to be mounted at most 0.4mm from the ground as the diagram below shows in order to obtaining a good level of output.

Sensor Testing

For future improvement of the testing procedure, the sensors will be tested using a reflective surface and not white white paper.  The reason being that the group reckons the paper must have been unable to reflect the infrared light from the sensor properly. Other suggestions for improvement  included changing the sensors to one that has a better range and cost efficient.

  • If the correct voltage waveform is obtained, proceed to put a white reflective object in front of the sensors. Observe the voltage waveform on the oscilloscope. The voltage level should decrease to around 0V.
Sensor Testing

Conditions for Testing the sensors

If a correct voltage is obtained, that means that the sensors circuitry is ready to interface with the motherboard for further software testing.

Problem encountered during testing of the Sensors

  • Sensors are  always in the high state . Find out that the sensors is faulty.
  • Sensitivity of the sensors is not good. Had to change the resistor at the LED to a higher value for the best sensitivity.
  • Some open connection. Due to poor soldering skill
  • Wires tend to break off easily if the solder is hard and brittle.


  • Change the sensors to ones that have a wider  sensing range.

Improvements and  the design

The crucial parts of the designs that may need improvements are the sensor positioning and the software manipulation. The sensors must be positioned at a suitable position for the robot to work. The program software on the other hand can be manipulated to suit the requirements. For example the speed of the robot can easily be adjusted by altering the delay time in the software program.

Programming Serial Port cable . This cable links the Mitsubishi Board to the Computer when it is being programmed. Hence acts as a transfer path via which a compiled software program code, written in C program on the computer gets loaded on to the M16C/62 Chip.
The entire system is now stacked up using spacers, screws and the connection cable. The following is a complete structure of the Robot machine, Programmed and Ready to go.

Software sample code

#define Chip_30602

#include “iom16c62.h”

int stepper1_data []={1,2,4,8};

int stepper2_data []={128,64,32,16};//one stepper must be reversed due to the flip

/* General purpose delay routine */

void delay (int d)


  int i;

  for (i=0;i<d;i++);


void main (void)


  char  value1, value2;

  int counter=0;     /* number of pulses sent */

  int index1=0;      /* array index for step pattern */

  int index2=0;

                     /*Analogue input*/

      ADCON2 = 0x01;      //enable sample and hold

      ADCON0 = 0x08;      //AD0 single channel, repeat mode

      ADCON1 = 0x30;      //VREF enabled, 8bit mode

      ADCON0.6 = 1;       //start A-D conversion – Note repaet mode

    /* setup port 2 (stepper motor) to all output */ 

  PD2 = 0xFF;  

  for(;;) //infinite loop


      value1 = AD0;   /*analogue output*/

      value2 = AD1;


      DA0= value1;

      DA1= value2;

      //verify analoge input voltage between 2 and 3 volts

      //switch on LED

      //check postion of right sensor

      if ((102 < value1) && (value1 < 153)) 


      confgure LED port 0

      apply motion to right stepper

        P2=stepper1_data[index1];  /* send data to port */

        delay (30000);            /* stepper motor delay */

        index1++;                 /* increment array index */

        if(index1>3) index1=0;     /* and make it wrap to 0 at 4 */

        counter++;               /* increment total pulse counter */

          PD0=0xff;   // port 0, all dirctions OUTPUT

          PD1=0xff;   // same for port 1 */

          P0=0xf9;   // 7 segment diaplay pattern for ‘1’ but negative logic

          P1=0x01;   // LED display number 1 enabled*/


      //verify analoge input voltage not between 2 and 3 volts

      //switch off LED

      //check postion of right sensor

      else if( 153 < value2 < 102)


        //apply motion to right stepper

          P2=stepper2_data[index2];  /* send data to port */

          delay (30000);            /* stepper motor delay */

          index2++;                 /* increment array index */

          if(index2>3) index2=0;     /* and make it wrap to 0 at 4 */

          counter++;               /* increment total pulse counter */




Leave a Reply

Your email address will not be published. Required fields are marked *

Please support the site
By clicking any of these buttons you help our site to get better
Social PopUP by Timersys