Home
Kevin Gallagher

Kevin Gallagher showing off his Fire Fighting Robot

Side view of Kevin's Fire Fighting Robot Flames' death view of Kevin's Fire Fighting Robot.



Mikroelectronica MikroC code
//////////////////////////////
/////Stuff/////////////////////
///////////////////////////////
int x;
char text[20];
unsigned int Left_IR;
unsigned int Right_IR;
unsigned int Centre_IR;
unsigned int sharps;
int twitch;

///////////////////////////////
/////Moving the Bot////////////
///////////////////////////////

/////Thataway//////////////////
void Forward()
{
    PORTC = 0b11000011;
    delay_ms(500);
    PORTC = 0;
    delay_ms(20);
}
/////---->/////////////////////
void Right()
{
    PORTC = 0b11000101;
}
/////<----/////////////////////
void Left()
{
    PORTC = 0b10100011;
}
/////Backwards/////////////////
void Back()
{
    PORTC = 0b10100101;
}
/////Cease and Desist!/////////
void Stop ()
{
    PORTC = 0;
    delay_ms(1000);
}
///////////////////////////////
/////Turret Movement///////////
///////////////////////////////

/////Straight Ahead////////////
void Center()
{
    x = 12;
    while(x > 0)
    {
      PORTB.F5 = 1;
      Delay_us(1450);
      PORTB.F5 = 0;
      PORTC = 0b11000011;
      delay_ms(19);
      x = x - 1;
    }
      //Centre_IR = Adc_Read(0);
      sharps = Adc_read(0);
       if (sharps > 200)
       {
       PORTC = 0b11000101;
       delay_ms(500);
       sharps = 100;
       }
}
/////Turret ---->//////////////
void FarRight()
{
    x = 12;
    while(x > 0)
    {
      PORTB.F5 = 1;
      Delay_us(850);
      PORTB.F5 = 0;
      PORTC = 0b11000011;
      delay_ms(19);
      x = x - 1;
    }
      //Right_IR = Adc_Read(0);
      sharps = Adc_read(0);
       if (sharps > 350)
       {
       PORTC = 0b10100011;
       delay_ms(250);
       sharps = 100;
       }

}
/////Turret <----//////////////
void FarLeft()
{
    x = 16;
    while(x > 0)
    {
      PORTB.F5 = 1;
      Delay_us(2050);
      PORTB.F5 = 0;
      PORTC = 0b11000011;
      delay_ms(19);

      x = x - 1;
    }
     //Left_IR = Adc_Read(0);
     sharps = Adc_read(0);
     sharps = Adc_read(0);
     sharps = Adc_read(0);
       if (sharps > 350)
       {
       PORTC = 0b11000101;
       delay_ms(50);
       sharps = 100;
       }

}

///////////////////////////////
/////LCD Display///////////////
///////////////////////////////
void LCD()
{
//  text = "Mr Cool ";
  Lcd_Init(&PORTB);         // Initialize LCD connected to PORTB
  Lcd_Cmd(Lcd_CLEAR);       // Clear display
  Lcd_Cmd(Lcd_CURSOR_OFF);  // Turn cursor off
  Lcd_Out(1, 1, text);      // Print text to LCD, 2nd row, 1st column
//  text = "is cool!";
  Lcd_Out(2, 1, text);
}

///////////////////////////////
/////Sensor Stuff//////////////
///////////////////////////////

/////Left Sensor///////////////
void SensorDisplayL()
{
  Left_IR = Adc_Read(2);
}
/////Right Sensor//////////////
void SensorDisplayR()
{
  Right_IR = Adc_Read(1);
}
/////Centre Sensor/////////////
void SensorDisplayC()
{
  Centre_IR = Adc_Read(3);

}
/////Comparison////////////////
void SensorCompare()
{
  //Lcd_Cmd(Lcd_CLEAR);
Left_IR = Adc_Read(2);
Right_IR = Adc_Read(1);
Centre_IR = Adc_Read(3);
  //SensorDisplayL();     //Leftie
  //SensorDisplayR();     //Rightie
//  SensorDisplayC();     //Centre

    if(Right_IR > Centre_IR)        //Centre has less than right
    {
      if(Left_IR > Centre_IR)     //Centre has less than left
      {
        Forward();
        delay_ms(500);
      }
      if(Left_IR < Centre_IR)     //Centre has more than left
      {
        Left();
        delay_ms(500);
      }
    }
    if(Left_IR > Centre_IR)        //Centre has less than left
      {
        if(Right_IR > Centre_IR)    //Centre has less than right
        {
          Forward();
          delay_ms(500);
        }
        if(Right_IR < Centre_IR)    //Centre has more than right
        {
          Right();
          delay_ms(500);
          //Forward();
        }
      }
}

/////Comparison////////////////
void Sensorscan()
{
  //Lcd_Cmd(Lcd_CLEAR);
Left_IR = Adc_Read(2);
Right_IR = Adc_Read(1);
Centre_IR = Adc_Read(3);


    if(Right_IR < 600)        //Centre has less than right
    {
        PORTC = 0b11000101;
        delay_ms(500);
    }
    if(Left_IR < 600)        //Centre has less than left
      {
          PORTC = 0b10100011;
          delay_ms(500);
      }
}

/////Servo 2///////////////////
void Pull()
{
    x = 60;
    while(x > 0)
    {
      PORTB.F4 = 1;
      Delay_us(250);
      PORTB.F4 = 0;
      delay_ms(20);
      x = x - 1;
    }
    PORTC = 0b10100011;
    delay_ms(20);
    PORTC = 0b11000101;
    delay_ms(20);
    x = 40;
    while(x > 0)
    {
      PORTB.F4 = 1;
      Delay_us(2000);
      PORTB.F4 = 0;
      delay_ms(20);
      x = x - 1;
    }
}
///////////////////////////////
/////Main Portion//////////////
///////////////////////////////
void Main ()
{
  TRISA = 0b00011111;
  TRISB = 0;
  TRISC = 0;
  PORTC = 0;
  ADCON1 = 10000000;

//Centre_IR = 401;                             //           |\
  SensorDisplayC();                            //           | |
  while(1)                                     //           | |>    ___
  {                                            //           | |   _|___|_
    //SensorCompare();                         //           |/|    (o_o)
    if(Centre_IR > 600)                        //             |     _|_
    {                                          //             |    |   |
      Center();                                //             o----|   ||
      FarLeft();                               //             |    |   ||
      Center();                                //             |    |   ||
      FarRight();                              //             |    |   ||
      Sensorscan();                            //             |    |   ||
    }                                          //             |    |   |o
    if(Centre_IR < 599)                        //             |    |___|
    {                                          //             |    |   |
                                               //             |    |   |
      SensorCompare();                         //             |   _|   |_
      if(Centre_IR < 300)
      {
        Stop();
        Pull();
        Sensorscan();
      }
//      Center();
    }
  }
}
Material List
  • (1) PicProc Board and PIC16F876
  • (2) Hitec HS-311 Servo
  • (1) Sharp Sensor
  • (1) Mini Motor Driver
  • (6) Molex Cable
  • (1) 4 AA Battery case
  • (1) 9 V Battery case
  • (4) IR Photo Transistor
  • (4) 39K Resistor
  • (6) Misc Molex ends and pins
  • (1) CO2 Duster
  • (1) Tamiya 4 speed Gear Box
  • (1) Universal Plate Set
  • (1) Universal Arm Set
  • (1) Track and Wheel Set
  • (1) Universal Plate Set
  • (8) 1.25" Standoffs (92745A327)
  • (2) 1.50" Standoffs (92745A328)
  • (6) 0.75" Standoffs (92745A324)
  • (4) 0.25" Standoffs (92745A320)
  • (2) Angle Braces (1556A24)
  • Misc screws and hardware