NPEDUCATIONS, Electronic circuits development, electronics tutorials, microcontroller tutorials and projects, advanced microcontroller (ARM) based tutorials and projects, Embedded c development, Embedded c for ARM cortex M, Intel IoT based projects, IoT projects, CC3200 launch pad projects, MSP430 Launchpad tutorials and projects, Tiva C launch pad tutorials and projects, 8051 tutorials and projects, sensor interfacing with microcontroller tutorials, data communications and networking tutorials, peripheral interfacing with microcontroller, led message scrolling display, arduino based tutorials and projects, intel galileo based tutorials and project, ADC interfacing tutorials, LED Blinking, LCD interfacing, Embedded System tutorials and projects, B.tech projects, M.tech projects, online Embedded C training

Automatic fire detection system with water sprinkler system

Intelligent Fire Detection system with automatic water sprinkler system - Project with code
Automatic fire detection system with water sprinkler system using msp430 mcu
Automatic fire detection system with water sprinkler system using MSP430 MCU


Introduction:

In this project, a fire sensor is used to detect the occurrence of the fire in the surrounding environment. If you want abstract for this project, then visit INTELLIGENT FIRE DETECTION SYSTEM WITH AUTOMATIC WATER SPRINKLER SYSTEM USING MSP430 .Actually here a fire sensor is connected to a circuit which produces a digital output when the fire is detected. This digital output is connected to the MSP430G2553 microcontroller pin as interrupt signal. A motor driven program or a part of it is written in the interrupt service routine which is executed when the sensor digital output is high (interrupt signal to MSP430). A water sprinkler mechanism is connected to the shaft of the dc motor, which will sprinkle the water when the fire is detected by the sensor (fire extinguisher). A 16x2 LCD is also interfaced with MSP430G2553 to show the status about the fire occurred or not in more effective way. Instead of the LCD one can use a buzzer or speaker to make the project output more effective by playing sound using the buzzer. But in this project, both LCD and Buzzer are used to make the project output more beautiful.
To achieve this digital output, the sensor is connected to the LM348 op amp and a preset is used to fix the threshold level. Therefore the LM348 acts as a comparator and its output is either logic High or logic Low depend up on the sensor output and preset value. Complete details about the gas/fire sensor and its digital interface circuit will be discussed in the next coming articles, because to make this article short and simple.

Gas sensor and its digital circuit:
Gas or Fire sensor PCB board with digital output
Gas or Fire sensor with digital output



Circuit Diagram:
Figure 1.1 : circuit diagram for the Automatic fire detection system with water sprinkler system
circuit diagram for the Automatic fire detection system with water sprinkler system using msp430
Figure 1.1 : circuit diagram for the Automatic fire detection system with water sprinkler system

Circuit Explanation:
A 3.3V power supply for the MSP430 can be achieved by connecting 3.3V zener regulator in shunt and a 68ohms resistor is connected in series to the 12v supply. So that approximately 8-10 mA current will flow through the MSP430 when it is active otherwise it will flow through the zener diode.
I = (V1-V2)/Rs = (12-3.3)/68ohms.
A 5v buzzer is connected to the P1.2 pin of MSP430 and the fire sensor digital output is connected to P1.3 of MSP430 as shown in the above figure 1.1. The power on reset circuit with a 47kohms resistor and 1nf capacitor is connected to reset pin (RST) of MSP430 as shown in the above figure 1.1. The upper four MSB lines (D3 – D7) of the 16x2 LCD are connected to the Port2 upper pins (P2.3 to P2.7) and the Register Select (RS) line, Enable (EN) line are connected to P1.6 and P1.7 of the MSP430. In this circuit the read write (R/W) pin is connected to ground, because the microcontroller program is used to write the data on to the LCD, no read operation. A preset of 10k is connected to VEE line of the LCD and a 1k resistor is connected in series to it as a protection resistor. The 1k resistor protects LCD by not allowing more current when the adjustable preset pointer is at minimum position. ULN2803 current sinker allows maximum of 500mA current and is used to drive the dc motor by connecting the one end of it to ground via 500mA fuse. When P2.3 pin of the MSP430 is at logic high which is connected to the ULN2803 input, then the corresponding output pin is connected to ground and the motor current start flowing through the motor from the 12V DC supply.

Operation:
When circuit power is up, the LCD will display a message “No fire is detected”. When the fire sensor detected the fire, its output turn to logic HIGH and it acts as an interrupt signal to MSP430. Then immediately, corresponding ISR function is executed in the MSP430 and set the motor pin to high, which in turn enable the input pin of the ULN2803. Therefore the ULN2803 drives the motor by allowing motor current via 500mA current. Now the LCD updates its status, by displaying the message “Fire detected” and at the same time the buzzer will alarm about the fire occurred. A water sprinkler mechanism is connected to the motor to sprinkle the water on fire to light off.

Firmware Program Code Explanation:

The firmware code starts with the Basic Clock System initialization of the MSP430 and the MCLK and SMCLK frequency are initialized to 2MHz. This clock frequency can be achieved by following the below steps.

1. Select the basic clock frequency range and DCO frequency range to 8MHz.

Code: BCSCTL1 = CALBC1_8MHZ;
           DCOCTL = CALDCO_8MHZ;

2. Choose SMCLK to driven by MCLK by setting SELM_0 bit. And divide the           MCLK and SMCLK by a pre-scale factor of 4 by setting DIVM_2 and DIVS_2.
    
               SELMx bits – 00 – DCOCLK.
                                       01 – DCOCLK.
                                       10 – XT2CLK.
                                       11 – LFXT1CLK or VLOCLK.

Code: BCSCTL2 |= DIVM_2  + SELM_0 + DIVS_2;   // SMCLK = MCLK = DCO/4                                                                                           //= 8M/4 = 2MHz

3. Each and Every port pin of the MSP430 got multiple functions. To choose the port pin as general purpose I/O function

Code: P2SEL = 0;
 P2SEL2 = 0;

4. Define the necessary pins as input and output. If the port pin is initialized to 1, then it is output otherwise it is input.

                    Code:  P2DIR = 0xF0; // make all port2 upper pins as output P2.7, P2.6, P2.5,                                                             //  P2.4 are LCD pins
                                P1DIR |= 0xC7; // P1.5 - gas Sensor(input), P1.6 and P1.7 for LCD, P1.0                                                              //- LED output, P1.3 - Motor , P1.2 - Buzzer
                                P1OUT = 0X00;
                                P2OUT = 0x00; P2OUT = 0x00;

5. Initialize the P1.5 as an interrupt signal.

Code: P1IE |= 0x20;                             // P1.5 interrupt enabled
                              P1IES &= ~0x20;                            // P1.5 low to high edge
                              P1IFG &= ~0x20;                           // P1.5 IFG cleared

6. Initialize the 16x2 LCD as two line, 5x7 matrix – see the program below

7. In the Interrupt service routine, I have used the P1.0 pin as a status bit. Because the P1.5 pin is initialized to detect the low to high edge transition as interrupt signal. But our sensor output will either high or low depend upon the fire detected or not. When fire is detected by the sensor, then it will produce a low to high transition on the P1.5 as interrupt and enable the P1IFG flag. Therefore corresponding ISR will be called which will update the status of the LCD, start the motor, buzzer sounds the alarm.
But when the fire is lited off, then the sensor will produce logic high to low transition on the P1.5 line, but this pin won’t recognize the interrupt because it is initialized to respond for high to low. So the motor won’t stop running, buzzer won’t stops the sound, no update in the LCD still displaying the message that “fire detected”.
For this reason, I have used a port pin P1.0 to know the status of the fire sensor, when the fire is detected then P1.0 is set to 1 otherwise it is cleared. Hence, I am going to change the edge transition from high to low and low to high depend up on the P1.0 status. So that, the interrupt service routine is called for both high to low and low to high transition.
                    Code:          // Port 1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
          P1OUT ^= 0x01;  // P1.0 = toggle output,  it is just like a                                            //bench mark, when P1OUT is 1, then                                                //motor will on otherwise it is off

          if(P1OUT & 0x01 == 0x01)
          {
                   status = 1;   // Fire detected
              P1IES |= 0X20;  // Change the interrupt edge detection                                             //to high to low transition
          }
          else
          {
                   status = 0;      // no Fire detected
                  P1IES &= ~0X20; // Change the interrupt edge                                                            //detection to low to high transition
          }

          P1IFG &= ~0x20;                           // P1.5 IFG cleared

}

OUTPUT:

Output for Automatic fire detection system with water sprinkler system using msp430 mcu
Output for Automatic fire detection system with water sprinkler system


Program Code:

/******************************************************************************
 * Title: Intelligent Fire detection system with automatic water sprinkler system
 * Author: kiranvarma
 * My favourate blogs
 * http://www.npeducations.com
 * http://www.npprogrammers.com or http://www.npprogrammers.blogspot.com
 * http://www.npfoods.com or http://www.npfoods.blogspot.com
******************************************************************************/

#include  "msp430g2553.h"
#include  "stdio.h"
#include  "string.h"
#include "stdlib.h"
#include "MSP430_LCD.h"

#define delay_value 500
unsigned char status = 0;

void main(void)
{
 WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

 // initialize the clock frequency and DCO frequency to 8MHz by setting BCSCTLx registers
 BCSCTL1 = CALBC1_8MHZ;
 DCOCTL = CALDCO_8MHZ; // Set DCO

 //obtain 2MHz clock frequency
 BCSCTL2 |=  DIVM_2  + SELM_0 + DIVS_2;               // SMCLK = MCLK = DCO/4 = 8M/4 = 2MHz

 // Making all the port2 pins as basic I/O functionality
 P2SEL = 0;
 P2SEL2 = 0;

    // define necessary input and output pins
 P2DIR = 0xF0;                            // make all port pins as output P2.7,P2.6,P2.5,P2.4 are LCD pins
 P1DIR |= 0xC7;                           // P1.5 - gas Sensor(input), P1.6 and P1.7 for LCD, P1.0 - LED output, P1.3 - Motor , P1.2 - Buzzer
 P1OUT = 0X00;
 P2OUT = 0x00;
 P1IE |= 0x20;                             // P1.5 interrupt enabled
 P1IES &= ~0x20;                            // P1.5 low to high edge
 P1IFG &= ~0x20;                           // P1.5 IFG cleared


 // LCD first time initialize code
 delayms(1500); // wait for more than 15ms after supply rises to 4.5V
 send_cmd(0x30);
 delayms(4000); // wait more than 4.1ms
 send_cmd(0x30);
 delayms(1000); // wait more than 100us, but delayms(1) will provide 1ms
 send_cmd(0x30);
 delayms(1000);
 send_cmd(0x02); // return to home
 delayms(1000);

 LCD_Init(); // LCD initialization
 delayms(500);


 send_cmd(0x01);
 delayms(delay_value);
 send_cmd(0x80);  // clear display
 delayms(delay_value);
 send_string("Fire Detection System:");
 delayms(60000);
 delayms(60000);
 __enable_interrupt(); // enable the global interrupt


 while(1)
 {

  if(status == 1)
  {
   P1OUT |= BIT2; // enable motor
   P1OUT |= BIT1; // buzzer motor
   send_cmd(0x01);
   delayms(delay_value);
   send_cmd(0x80);
   delayms(delay_value);
   send_string("Fire Detected!");
   delayms(60000);
   delayms(60000);

  }
  if(status == 0)
  {
   P1OUT &= ~BIT2; // enable motor
   P1OUT &= ~BIT1; // buzzer motor
   send_cmd(0x01);
   delayms(delay_value);
   send_cmd(0x80);
   delayms(delay_value);
   send_string("No Fire Detected!");
   delayms(60000);
   delayms(60000);



   //stop the timer
  }


 }// End of while

} // end of main


// Port 1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
 P1OUT ^= 0x01;                            // P1.0 = toggle output,  it is just like a bench mark,
 //when P1OUT is 1, then motor will on otherwise it is off

 if(P1OUT & 0x01 == 0x01)
 {
  status = 1;   // Fire detected
  P1IES |= 0X20;  // Change the interrupt edge detection to high to low transition
 }
 else
 {
  status = 0;     // no Fire detected
  P1IES &= ~0X20; // Change the interrupt edge detection to low to high transition
 }

 P1IFG &= ~0x20;                           // P1.5 IFG cleared

}



LCD CODE:
#include "MSP430_LCD.h"
#include  "msp430g2553.h"
#define delay_value 500
void LCD_Init(void)
{
 send_cmd(0x28);       // configuring LCD as 2 line 5x7 matrix in 4-bit mode
 delayms(delay_value);
 send_cmd(0x0E);   //display on, cursor blink
 delayms(delay_value);
 send_cmd(0x06);  // auto increment of cursor
 delayms(delay_value);
 send_cmd(0x01);  // clear display
 delayms(delay_value);

}

void send_cmd(unsigned char command)
{


 P2OUT &= 0X00;

 P2OUT &= 0x00; // make upper bits of port as zero
    P2OUT =(command);    //mask lower nibble and send upper nibble

     P1OUT &= ~0x40;                        // RS = 0 for command, P1.6 0x40
     //RW is grounded
     P1OUT &= ~0x80;                        //EN = 0, P1.7, 0x80
     delayms(delay_value);
     P1OUT |= 0x80;                        // EN = 1, P1.7, 0x80
     delayms(delay_value);
     P1OUT &= ~0x80;                        //EN = 0, P1.7, 0x80
     delayms(delay_value);

     P2OUT &= 0x00; // make upper bits of port as zero

     P2OUT =(command<<4 data-blogger-escaped-0="" data-blogger-escaped-0x00="" data-blogger-escaped-0x40="" data-blogger-escaped-0x80="" data-blogger-escaped-and="" data-blogger-escaped-as="" data-blogger-escaped-bits="" data-blogger-escaped-char="" data-blogger-escaped-character="" data-blogger-escaped-command="" data-blogger-escaped-delay_value="" data-blogger-escaped-delayms="" data-blogger-escaped-en="1," data-blogger-escaped-for="" data-blogger-escaped-grounded="" data-blogger-escaped-i="" data-blogger-escaped-if="" data-blogger-escaped-is="" data-blogger-escaped-lower="" data-blogger-escaped-make="" data-blogger-escaped-mask="" data-blogger-escaped-nibble="" data-blogger-escaped-of="" data-blogger-escaped-p1.6="" data-blogger-escaped-p1.7="" data-blogger-escaped-p1out="" data-blogger-escaped-p2out="(String[i]<<4);" data-blogger-escaped-port="" data-blogger-escaped-rs="0" data-blogger-escaped-send="" data-blogger-escaped-send_char="" data-blogger-escaped-send_string="" data-blogger-escaped-tring="" data-blogger-escaped-unsigned="" data-blogger-escaped-upper="" data-blogger-escaped-void="" data-blogger-escaped-while="" data-blogger-escaped-x40="" data-blogger-escaped-x80="" data-blogger-escaped-zero="">=16)   // If the number of characters in the string > 16, then the below command automatically
  send_cmd(0x18);  // Shift the display right side
  delayms(40000);   // 100 millisec delay
  i++;
 }

}


void delayms(unsigned int value)
{
 unsigned int i;
 for(i=0;i

2 comments :

Thanks for visiting NPEDUCATIONS. We will contact you soon

2 comments :

maria abegail hilario said...

what software did you use?

Tyson Harold said...

very nice information

Post a Comment

Thanks for visiting NPEDUCATIONS. We will contact you soon

If you really like this tutorial, Don't forget to give the comment or please subscribe to the RSS feed by submitting your E-mail or like our Facebook page.
Related Posts Plugin for WordPress, Blogger...

 
Powered by Blogger