Wednesday, 14 December 2011

Cybertron team - Line Following Robot Pahang Malaysia University 2011

yeah~this's time i write down how to do line following robot using PIC and own sensor + C++ programming, there are about 30 teams join this competition before study week....

1st of all, I found zinc material as body structure, using IR transmitter and receiver as sensor, and PIC18f4550 and sealed lead acid 12v 1.2 Ah, geared motor 103 rpm and 100 torque.

the design of circuit are randomly, just hope that it can operate well and there are no problem (but actually in last days of preparation I faced motor driver wiring solder not so well causes malfunction, but later it's ok :) )


another photo is my design of circuit include L293DNE and  MC74HCT14AN~ my circuit  putting LM7805 to make the voltage 5volt constantly. and this is simplest circuit to make line following robot just following the ports that prepare from PIC18F4550~(actually i want do USB interface but because lack information and skill on programming so i cancel the USB interface ady~)

I'm using RA0 - 7 to use as output (motor) and RB0 - 7 use as input (sensor), i using 2 IR sensors and 2 motor so is 4 output for move the body of structure. then power supply area is 12V change to 5V so that PIC18f4550 and MC74HCT14AN got supply of 5V. L293DNE use 12V as power supply as geared motor so that the motor can run with maximum speed (although it can run more faster with higher voltage but it will damaged very fast.)

Next, come to body design. we are proud of our robot's body because it had won "Best Design Engineering" in this competition. I dont have the completed part of photo but I captured the body after the competition.


hope our robot's design didn't disappointing to readers :), our robot was designed by Liew Khee Yan (I encouraged him to think of strong design so that we can win the prize and we did it !!) by draft paper that i estimate all the measurement of robot so that the holes and parts can join together perfectly.

using zinc material to do body (I want to find aluminum material but it cost highly and the material is not easily been bent) and the base is zinc that harden, the upper parts actually are low strength of zinc material so that I can easily bent the material to become parts :).

the result come out such as the picture at below:


 then come to sensor part, the circuit for ir sensor show at below(simplest circuit for ir sensor :) ):


The operation of circuit is give supply 5 Volt to IRED and IR receiver so that IRED can convert electric current into infrared out and ir receiver to receive the infrared to let current flow through ir receiver. we can put one wires between ir receiver and 47 k ohm so that when ir receiver didn't receive infrared red, the current flow through the signal wires in 5 volt; when ir receiver receive infrared red, the voltage will flow in parallel through ir receiver and signal wires so that signal in low voltage (my measurement show voltage in 1V which is lower than 4 volt).

I placed the sensor in front of robot to detect the white area, the dimension of black line is 3cm width and 1.11m length. placed the sensor about 3-3.5cm so that it detect the white area; my program write down when sensor detect black line, the motor will turn left/right to make it take a turn

example of my program using PIC C Compiler and melab programmer to interface the program into PIC.

#include <18F4550.h>                  //define PIC library file here
#fuses HS,NOWDT,NOPROTECT,NOLVP      //define protection function
#use delay(clock=4000000)           //define oscillation frequency

#DEFINE  CCP1         PIN_C1
#DEFINE  CCP2         PIN_C2
#define  motor1_cw    PIN_A3         // LET PIN_A0 MEAN CLOCKWISE ROTATION (RIGHT MOTOR)
#define  motor1_ccw   PIN_A2        // LET PIN B1 MEAN ANTI-CLOCKWISE ROTATION
#DEFINE  motor2_cw    PIN_A0       // LET PIN A2 MEAN CLOCKWISE ROTATION (LEFT MOTOR)
#DEFINE  motor2_ccw   PIN_A1      // LET PIN A3 MEAN ANTI-CLOCKWISE ROTATION
#define  sensor1      PIN_B2
#DEFINE  SENSOR2      PIN_B3

void main()                         //main program starts here
{

/*local variable*/

/*Port Initialize*/

setup_timer_2 (T2_DIV_BY_4,254,1);
setup_ccp1(ccp_pwm);                   //PIC 16 TO L293D 1    
setup_ccp2(ccp_pwm);                  //PIC 17 TO L293D 2
set_tris_a (0X00);                   // SET RA TO BECOME OUTPUT
set_tris_b (0Xff);                  // SET RB TO BECOME INPUT

//STARTING
output_a (0X00);
output_b (0xFF);

//main program
delay_ms (100);                    //delay 2 second for user to left the competition

OUTPUT_HIGH(PIN_B0);                        // EN_1 & EN_2 high //
OUTPUT_HIGH(PIN_B1);

//FORWARD
OUTPUT_low(PIN_A2);                       //FORWARD RIGHT MOTOR
OUTPUT_high (PIN_A3);

SET_PWM1_DUTY(180);                        // SPEED OF MOTOR

OUTPUT_high(PIN_A0);                       //FORWARD LEFT MOTOR
OUTPUT_low (PIN_A1);

SET_PWM2_DUTY(180);                        // SPEED OF MOTOR


WHILE(TRUE)
{


IF (!INPUT(PIN_B2))
{
OUTPUT_LOW  (PIN_A2);                       //forward left MOTOR
OUTPUT_high (PIN_A3);

SET_PWM1_DUTY(170);                        // SPEED OF MOTOR

OUTPUT_low(PIN_A0);                       //stop right MOTOR
OUTPUT_LOW (PIN_A1);


SET_PWM2_DUTY(180);                        // SPEED OF MOTOR

delay_ms(50);
}

else if(!input(PIN_B3))
{
OUTPUT_low (PIN_A2);                     //stop left motor
OUTPUT_low  (PIN_A3);

SET_PWM1_DUTY(170);                        // SPEED OF MOTOR

OUTPUT_high (PIN_A0);                       //forward right MOTOR
OUTPUT_LOW (PIN_A1);

SET_PWM2_DUTY(180);                        // SPEED OF MOTOR

delay_ms(50);
}

else if(!input(PIN_B2) && !input(PIN_B3))
{

}
}}

that's it for my line following robot, we cybertron team took photo as memories we are 1 team to compete opponent with our best!! ><




2 comments:

  1. what software that u use for this robot?
    mplab ?

    ReplyDelete
  2. 1.PIC C Compiler

    http://www.ccsinfo.com/content.php?page=compiler-details

    2.install into microchip with melabs Programmer Beta

    http://melabs-programmer-beta.software.informer.com/

    ReplyDelete