Check Order Status  |   FAQ  |   Shopping Cart  |  Login  |  Register As Member   | 
 
Home  |   Our Product  |   Training  |   Forum  |   Project DIY  |   About Us  |   Contact Us  
  PR 5 - Line Following Robot
More about Project DIY...
Buy Project Set 5
Line Following Robot

Just 3 simple steps
1. Get the electronic components on hand and solder them up!
2. Building your robot.

3. Programming your robot.


Now that we have learn about IR sensor, we will move on to line following. In line following, you will have to know about IR sensor and also controlling motors. For this project, we will be applying what we have learnt in PR4. But first of all you will have to learn about controlling motor.

1. Controlling The Motor
1.1 Basic
When we say motor, we actually mean D.C. motor. This is because we are using D.C power supply for all of our projects. As an example, the PIC16F877A needs 5V DC to power it where else the Bluetooth modules needs 3.3V DC.

There are different types of DC motors available in the market such as DC geared motor, servo motor and stepper motor, but for this project, we will be focusing on servo motor Typical servo motors only allow 180° rotate which is not suitable for a wheeled robot to move from a place to another place. Thus, we had made some modification to the servo motor so that it can rotate 360° continuously. At the remaining of the text, we only concentrate on the continuous rotating servo motor.

To move the motor, just connect the power supply to the terminal on the motor while to move it in opposite direction, change the polarity of the connection between the power supply and the terminal. For this line following robot, we will be using two motors.

1.2 Motor driver L293D
In a line following robot, usually the motor is powered by a different source from the main circuit which is the microcontroller. Therefore, a additional component is required to enable the microcontroller to control the motors. For this project, we will be using L293D for this purpose. A servo motor usually needs 4.8V or 6.0V to operate. Higher voltage will generate more power to the motor, thus the motor will move faster and more powerful. For our application, 4.8V is more suitable.

From the schematics below, you can see that there is 6 pins connected to the microcontroller and 2 pins to each motor. Out of the 6 pins, 3 is for the left motor and the other 3 is for the right motor. Now lets concentrate on only 1 side of L293D, 3 pins for the microcontroller and 2 pins for the motor. Form the 3 pins, 2 pins is for the direction of the motor and 1 pin (connected to Pin C1 or C2) is for PWM which is to control the speed of the motor. If controlling of speed is not required, just provide this pin with 5 volt to enable it to move. The direction of the motors depends on the connection of the terminal but can also be determined through the program. Therefore, the sample program have to be modified according to your robot.

2. IR sensors

For this project, we will be using three pairs of IR sensors which will be attached to the bottom of the robot. These 3 sensors will be classified as left sensor, middle sensor and right sensor. A view of the placement of the sensors is as below:
The distance between 2 sensor depends on the width. The sensor should be placed in such a way that maximum distance of two sensors is equal to the width of the line as shown in figure below.
Tuning the comparator to trigger at certain intensity of infrared light is called “Teaching”. We will need a small Philips screw driver to tune the VR or preset to desire voltage. Place the robot on a white floor with black tape (line) as shown in picture:

To teach the robot for line detection, you may follow these steps:
  1. Adjust the robot so that the center infrared sensor is on top of white floor, make sure the wheels and castor of the robot touches the floor properly.
  2. Use the screw driver to adjust the preset of center sensor until indicator LED (center) light ON.
  3. Now adjust the robot to move the center sensor towards the black line where the reflection of infrared is poor.
  4. At this point, make sure the indicator LED is OFF. If the LED is still on, it means you have over tune the preset. Tune it back so that the indicator is OFF.
  5. Repeat step a. - d. for a few time and make sure the indicator LED ON and OFF correctly at the right spot.
  6. Repeat step a.- e. to "teach" left sensor and right sensor.
  7. Now your robot have been "taught".
Let’s see how this robot can follow line based of the response from each sensor. In our discussion, we will bypass the comparator by assuming that this robot have been taught. Once a particular sensor sensed black line, it will trigger the PIC.

Example of how the sensors function when the robot follows a black line on a white floor:
Sensor Response
Left Middle Right
W B W  Go Straight
B W W  Turn Left
W W B  Turn Right

Where, W = White
            B = Black

This is the concept of a line following robot. We can see that when the middle sensor detects the line, the robot will move forward. This is because the line is in the center of the robot. But when the left sensor or the right sensor detects the black line, this means that the robot have strayed from the line. If the robot strayed to the right, the left sensor will detect the line and the brain will react by turning left to go back to the line. As for the right sensor, it reacts in the opposite way.

3. Coordinating the motor and sensor
Now that you know how the sensors detect a line, we will continue to learn how the robot moves. The robot uses the concept of two separate moving wheels. The table below shows the combination of the wheels to move the robot in the desired direction.
  Left Wheel Right Wheel Movement
1 Forward Forward Forward
2 Backward Backward Backward
3 Forward Stop Right Turn
4 Stop Forward Left Turn
5 Forward Backward Sharp Right Turn
6 Backward Forward Sharp Left Turn
Prepare your donut board! Solder the SK40A onto your donut board. Follow the schematic that is shown below. If you are not sure, you can test it out first on your protoboard. It is advisable to start with the sensor part and test it first before soldering the motor part. This is because the sensors can be tested without the need to program the microcontroller. Test the sensors by placing it on a white surface and after that on a black surface, If the LEDs lights when it is placed on the white surface and turn off when placed on the black surface, then your sensors are connected correctly. You can then proceed with your motor part. Make sure that all the polarity of the components are according to the schematic.

      
The figure below shows the components for the movement of the line following robot. These components are only recommendations. Other motors, wheels, bases and castors that you like can also be used. In this chapter, we will be learning how to assemble all the components shown to build the robot.

2.1 Assembling the motors and base
i. First, screw the two motors on both side of the acrylic base included. Make sure that the shaft of the motors is positioned in the center of the base.

ii. After the motor have been mounted on the base, assemble the wheels onto the motor and screw it using the silver small screw that is included with the motor.

iii. For the castor, insert the bolts through the hole on the front and on the back and tighten the nuts.

2.2 Completing the Assembly
Stick the completed circuit (main circuit and sensors) and battery holders onto the base. The arrangement of the circuit and holders are completely dependant on your creativity.
After all robot have been completed, its time to program the microcontroller. For this project, we will be using C programming. The bootloader will still be used to program it (refer to PR3). There will be some changes when using MPLAB and Bootloader. Download the sample source code (PR5.hex) and try it on your robot. If the wheel does not turn in the required direction, just download the program (PR5.c) and change it to suit your robot.


3.1 MPLAB and PICC Lite

1. Start the MPLAB IDE program.



2. Set up a new project. Select Project-> Project Wizard then Click Next to continue.


3. Choose the correct device which is PIC16F877A and click Next to continue.


4. Select HI-TECH PICC Toolsuite as your language toolsuite from the Active Toolsuite drop-down menu. Click Next to continue




5. Enter a name and select the location for the project. Click Next to continue.


6. Click Next then select Finish to complete.






7. Download the sample program to the folder that you have created the project.

8. Right click on the Source files and select Add Files.




9. Add the PR5.c file.


10. Now you are ready to build your project. Select Project-> Build All or press CRTL+F10.

11. MPLAB will generate a HEX file that will be transferred to the PIC Microcontroller using the bootloader.


3.2 Bootloader
Please click here to review how to setup bootloader.

There is some changes when using C programming:
For source code written in C language with PICC Lite Compiler, there must be offset 200 in the “PICC Linker” option (Please refer to the pictures below).




3.3 Changing the program



The figure above is part of the program. If the robot is not moving in the direction that is supposed to, change the value for Port B that is circled in the program above. The four values represent RB7, RB6, RB5 and RB4 respectively. So to change the direction of the right wheel, change the value for RB7 and RB6 (first 2 digit) from 01 to 10. For the left wheel, change the value for RB5 and RB4 (next 2 digit) from 01 to 10. If the value is 00, that means that the motor stops. The value for ‘j’ has to be the same as Port B.


Buy Project Set 5

 
 


Last Update: 01 August 2008
Cytron Technologies Sdn Bhd [755563-V]