Saturday, July 7, 2018

Gas Leakage Detection System Using PIC18F452



In this project we will interface MQ2 gas leakage detector with PIC18F452. MQ2 is suitable for detecting H2, LPG, CH4, CO, Alcohol, Smoke or Propane. PIC18F452 is a popular micro controller in PIC18 series. If this sensor can sense a gas leakage then the buzzer will beep and if there is no gas leakage then buzzer won't beep. Also a LED will turn on and off, if gas leakage is detected. Also we will have a lcd to show that if the alarm is on or not. 


MQ 2 Gas Sensor




PIC18F452 Pin Diagram



To do this we need following software:

   1. MikroC pro for PIC (student verison)
   2. Proteus 8 professional
   3. PicKit 2

MikroC pro for PIC will be used for writing and compiling the code. Here we will use C language for programming. Proteus 8 professional will be used for the simulation and finally Pickit 2 will be used for burning the hex file in the PIC18F452  IC. 

To do this project we need following components;


   1. PIC18F452
   2. LED
   3. 16 MHz Crystal Oscillator
   4. Breadboard
   5. Wires
   6. 5V DC Power source
   7. MQ2 Gas Sensor
   8. 16*2 LCD
   9. BC547 
  10. Buzzer
  11. 150 ohm and 470 ohm resistor
  12. Header for connect LCD
  13. 10K potentiometer


CODE


// LCD module connections
sbit LCD_RS at RB7_bit;
sbit LCD_EN at RB6_bit;
sbit LCD_D4 at RB5_bit;
sbit LCD_D5 at RB4_bit;
sbit LCD_D6 at RB3_bit;
sbit LCD_D7 at RB2_bit;

sbit LCD_RS_Direction at TRISB7_bit;
sbit LCD_EN_Direction at TRISB6_bit;
sbit LCD_D4_Direction at TRISB5_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D6_Direction at TRISB3_bit;
sbit LCD_D7_Direction at TRISB2_bit;
// End LCD module connections

void main()
{
      unsigned int input = 0;
      TRISD = 0;                  // output register
      PORTD = 0;                  // output port

      ADCON1 =0x0E;               // Analog to digital converter turning on

      Lcd_Init();
      Lcd_Cmd(_LCD_CURSOR_OFF);

      Lcd_Cmd(_LCD_CLEAR);
      Lcd_out(1,1, " EEE 332 PROJECT");
      delay_ms(100);
      Lcd_out(2,1, "Micro Controller");
      delay_ms(1000);
      Lcd_Cmd(_LCD_CLEAR);
      delay_ms(200);

      Lcd_Cmd(_LCD_CLEAR);
      Lcd_out(1,1, "   GAS LEKEAGE  ");
      delay_ms(100);
      Lcd_out(2,1, "DETECTION SYSTEM");
      delay_ms(1000);
      Lcd_Cmd(_LCD_CLEAR);
      delay_ms(200);

      Lcd_Cmd(_LCD_CLEAR);
      Lcd_out(1,1, "  DEVELOPED BY  ");
      delay_ms(100);
      Lcd_out(2,1, "   ABDUR ROUF   ");
      delay_ms(1000);
      Lcd_Cmd(_LCD_CLEAR);
      delay_ms(200);



      while(1)
      {

         input = ADC_read(0);           // Reading the ADC value from PORT A0

               if(input>=400)
         {

            PORTD = 0b11111111;         // Turning on LED on PORTB
            delay_ms(250);
            PORTD = 0b00000000;         // Turning off LED on PORTB
            delay_ms(250);
            Lcd_Cmd(_LCD_CLEAR);
            Lcd_out(1,1, "   GAS LEKEAGE  ");
            Lcd_out(2,1, "    DETECTED    ");
            delay_ms(1000);             // Turning on LED for 5 seconds

         }
               else
         {
            PORTD = 0b00000000;         // Turning off LED
            delay_ms(500);              // Turning off LED for 5 seconds
            Lcd_Cmd(_LCD_CLEAR);
            Lcd_out(1,1, "    ALARM OFF    ");
            Lcd_out(2,1, "  NO GAS LEAKAGE ");
      }
}

}



Schematic


Schematic 1


Schematic 2



Schematic 3



Schematic 4


No comments:

Post a Comment

Line Follower Robot using Arduino

This project was a part of Line Follower Robot Competition