Projects

Smart Fire Alarm

SMART FIRE ALARM

METHODOLOGY

Materials, Method and Diagram

Below contains a list of components used and also a detailed explanation of the diagram above.

List of components used:

  • Arduino Nano (microcontroller)
  • SIM800L (GSM module)
  • Flame sensor
  • LM2596 Module (Buck converter)
  • LED
  • Transistor
  • Buzzer
  • Resistors
  • Vero board
  • Wires
  • Battery

Arduino Nano: This is the most important device in a smart fire alarm system because this is where all the processing is done. This microcontroller is based on the ATmega328P chip and contains 14 digital input/output pins and 8 analog input pins. But for this project, only 6 digital pins were used. These are D2, D3, D4, D5, D6, and D7. Note that D means digital. D2 and D3 are used as custom serial pins to communicate with the SIM800L GSM module, D4 is connected to the flame sensor; D5 is connected to the buzzer while D6 and D7 are connected to the Red LED and Green LED respectively. The microcontroller reads the signal coming from the flame sensor and when pin D5 goes LOW, it means the flames sensor has sensed fire, the microcontroller immediately triggers the buzzer by making D5 HIGH, turns on the Red LED by making D6 HIGH, after which it will communicate to SIM800L GSM module to send a message “fire detected…! Take action immediately” and also make a call to the phone number which has been programmed into it. After making the call, if the fire is no longer present, the microcontroller turns off the RED led and the Buzzer by making D5 and D6 LOW. In this project, the word “Arduino nano” and “microcontroller” will be used interchangeably, when you see the word “microcontroller”,  please know that we are referring to Arduino nano.

SIM800L: This is a GSM compact module that provides GSM communication capabilities to our microcontroller. It contains a total of 12 Pins, but in this project, we will only make use of 5 pins, these are the VCC, GND, NET, TX, and RX. This GSM module operates on 3.4 to 4.4v, so the VCC pin is connected to the 3.7V buck converter. The NET pin which is also known as the antenna pin is connected to an antenna. TX and RX, which are the serial communication pins, are connected to D2 and D3 of the Arduino Nano respectively. Both pins receive commands from Arduino. For this project, the commands which these pins receive tell the GSM module to send a text message, make a phone call or end a phone call.

Flame Sensor: This is the input device of this system. It works by detecting the presence of infrared radiation of wavelength within the range of 760 nm – 1100 nm emitted by flames using a Photo Diode. This module consists of 3 pins, the VCC, GND, and D0 pins. The flame sensor power operation range is 3.3v to 5v. Thus, the VCC pin is connected to the 5v buck converter. D0 pin is the output pin which is normally HIGH; this pin goes LOW immediately after the flame sensor senses fire. The D0 pin is connected to the D4 of the microcontroller. 

LM2596 Module: This is a buck converter that is based on the LM2596 step-down voltage regulator IC. It is designed to take a higher input voltage and convert it to a lower output voltage. In this project, we have two buck converters which are used to step down the 12v coming from the battery to 3.7v and 5v. The 5v is to power up the microcontroller, LEDS, buzzers, and also flame sensor. The 3.7v is used to power up the GSM module.

LED:  The light-emitting diodes serve as indicators in this project. The Green LED is used to indicate booting and also power while the Red LED is used to give a visual notification that flame has been detected.

Transistor: BC547 is a general-purpose NPN bipolar junction transistor (BJT). In this project, it is used to interface the buzzer with the microcontroller. The buzzer cannot be connected directly to the microcontroller due to the reason that it needs 12v from the battery to produce a loud sound. Thus, the buzzer is connected to the collector of the transistor and the other terminal is connected to the positive terminal of the battery (12v), the emitter of the transistor is connected to the ground, the base of the transistor is connected to D5 of the microcontroller and the buzzer will only get activated when the base is goes HIGH.

Buzzer: This is a piezoelectric device that produces a sound when a voltage is applied across it. It gives out a loud sound when the microcontroller turns D5 HIGH. This only happens when the flame sensor detects fire.

Resistor: This component is used to reduce the flow of current to other components. The resistor used in this project is a 1k resistor. The Red LED, Green LED, and BC547 transistors are connected to 1k resistors each to reduce the amount of current flowing through them.

Vero board: This is also called a stripboard, it is a board that holds and connects the entire components together.

Wire: This is a conductor made of copper used to connect the components

Battery: This is our power source. We used a 12v battery for this project mainly to power the buzzer, thereby giving out a louder sound. The battery also serves as an input power for the buck converters.

Software and Code

The main advantage of a microcontroller is that it gives you the ability to program it according to your specific task, thereby reducing the number of components used, time, and also the size of the project. It also gives the ability to be able to interface your project with other sophisticated devices; this is why the Arduino nano was incorporated into this project. Arduino consists of hardware and also software known as Arduino IDE. In this project, the hardware used is Arduino nano while the software used is Arduino IDE.

Arduino IDE: This is an open-source integrated development environment (IDE) that is used for programming Arduino boards. The Arduino IDE provides a user-friendly interface for writing, compiling, and uploading code to Arduino boards. It uses the C++ programming language and provides a simplified programming environment with a simple syntax and a set of pre-defined functions for working with input/output pins, serial communication, timers, and other common microcontroller functions.

Below shows a screenshot of Arduino IDE:

Figure 2: A screen shot of Arduino IDE software

To use the Arduino IDE, we first click on the file option, and select new, this opens up a new page where we wrote our code. The Arduino IDE contains two important default functions, these are the “setup()” and “loop()” functions.

The setup() function is a predefined function that is called once when the Arduino board is powered on or reset. This function is used to initialize the board and any necessary components and to set the initial values of variables.

The loop() function is a predefined function that is called repeatedly by the Arduino board after the setup() function has been executed. This function is used to execute the main code of the program and to perform any necessary operations on the board or connected components.

After writing the code, Arduino nano was connected to the computer using a USB cable, the tools option was selected, then COM was also selected and the Arduino nano board was selected under the board option, the arrow button facing the Right was clicked in order to compile the code and also upload the code to Arduino nano board.

 Below shows the complete C++ code:

#include <SoftwareSerial.h>

//-----------------------------------------------------------------------------------

//Alert reciever's phone number with country code

const String PHONE_1 = "+2348187469738";

const String PHONE_2 = ""; //optional

const String PHONE_3 = ""; //optional

//-----------------------------------------------------------------------------------

//-----------------------------------------------------------------------------------

#define rxPin 2

#define txPin 3

SoftwareSerial sim800L(txPin, rxPin);

//-----------------------------------------------------------------------------------

//-----------------------------------------------------------------------------------

int Flame_sensor = 4;

int Flame_detected;

//-----------------------------------------------------------------------------------

//-----------------------------------------------------------------------------------

#define buzzer_pin 5

#define green_led 7

#define red_led 6

//-----------------------------------------------------------------------------------

void setup()

{

  //-----------------------------------------------------------------------------------

  //Begin serial communication: Arduino IDE (Serial Monitor)

  Serial.begin(115200);

  //-----------------------------------------------------------------------------------

  //Begin serial communication: SIM800L

  sim800L.begin(9600);

  //-----------------------------------------------------------------------------------

  pinMode(Flame_sensor, INPUT);

  //-----------------------------------------------------------------------------------

  pinMode(green_led, OUTPUT);

  pinMode(red_led, OUTPUT);

  pinMode(buzzer_pin, OUTPUT);

  digitalWrite(buzzer_pin, LOW);

  //this function delays the program to enable GSM module to boot

  boot();

  //----------------------------------------------------------------------------------

  Serial.println("Initializing...");

  //Once the handshake test is successful, it will back to OK

  sim800L.println("AT");

  digitalWrite(green_led, HIGH);

  delay(500);

  sim800L.println("AT+CMGF=1");

  digitalWrite(green_led, LOW);

  delay(500);

  digitalWrite(green_led, HIGH);

  //-----------------------------------------------------------------------------------

}

void loop()

{

  while(sim800L.available()){

  Serial.println(sim800L.readString());

  }

  Flame_detected = digitalRead(Flame_sensor);

  Serial.println(Flame_detected);

  //delay(100);

  //-----------------------------------------------------------------------------------

  //The fire is detected, trigger Alarm and send sms

  if (Flame_detected == 0)

  {

    digitalWrite(buzzer_pin,HIGH);

    digitalWrite(red_led, HIGH);

      Serial.println("Fire detected...! take action immediately.");

      send_multi_sms();

      make_multi_call();

    }

 //-----------------------------------------------------------------------------------

  //No fire is detected, turn OFF Alarm

  else

  {

    digitalWrite(buzzer_pin,LOW);

    digitalWrite(red_led, LOW);

    }

//-----------------------------------------------------------------------------------

}

//-----------------------------------------------------------------------------------

void send_multi_sms()

{

  if(PHONE_1 != ""){

    Serial.print("Phone 1: ");

    send_sms("Fire detected...! take action immediately.", PHONE_1);

  }

  if(PHONE_2 != ""){

    Serial.print("Phone 2: ");

    send_sms("Fire detected...! take action immediately.", PHONE_2);

  }

  if(PHONE_3 != ""){

    Serial.print("Phone 3: ");

    send_sms("Fire detected...! take action immediately.", PHONE_3);

  }

}

//-----------------------------------------------------------------------------------

//-----------------------------------------------------------------------------------

void make_multi_call()

{

  if(PHONE_1 != ""){

    Serial.print("Phone 1: ");

    make_call(PHONE_1);

  }

  if(PHONE_2 != ""){

    Serial.print("Phone 2: ");

    make_call(PHONE_2);

  }

  if(PHONE_3 != ""){

    Serial.print("Phone 3: ");

    make_call(PHONE_3);

  }

}

//-----------------------------------------------------------------------------------

//-----------------------------------------------------------------------------------

void send_sms(String text, String phone)

{

    Serial.println("sending sms....");

    delay(50);

    sim800L.print("AT+CMGF=1\r");

    delay(1000);

    sim800L.print("AT+CMGS=\""+phone+"\"\r");

    delay(1000);

    sim800L.print(text);

    delay(100);

    sim800L.write(0x1A); //ascii code for ctrl-26 //Serial2.println((char)26); //ascii code for ctrl-26

    delay(5000);

}

//-----------------------------------------------------------------------------------

//-----------------------------------------------------------------------------------

void make_call(String phone)

{

    Serial.println("calling....");

    sim800L.println("ATD+ "+phone+";");

    delay(20000); //20 sec delay

    sim800L.println("ATH");

    delay(1000); //1 sec delay

}

void boot()

{

  for (int i = 0; i < 11; i++)

  {

  digitalWrite(green_led, HIGH);

  delay(500);

  digitalWrite(green_led, LOW);

  delay(500);

  }

}

Below is the explanation of each section of the code: 

This above is the Void option that will run once when Arduino is powered up. The first 4 lines of this code are used to initialize the connection between Arduino nano and the computer then between the GSM module and Arduino nano. The numbers in the “ Serial.begin(115200)” and “sim800L.begin(9600)”  functions are used to define the bandwidth in which they communicate. pinMode() function is used to set the pins to either output or input. The rest codes in this setion are used to initialize the SIM800L GSM module.

The “ #include <SoftwareSerial.h>”  is a preprocessor directive in the Arduino programming language that allowed us to include the SoftwareSerial library in our sketch. The serial port D0 and the D1 of the arduino could not be used, because it already serves as a serial communication port for the computer to arduino nano. The rest code above tells arduino where the various components are connected to. For example: “#define red_led 6” tells the microcontroller that the red LED is connected to digital pin 6.

The loop() function is the last default function in the code. It also contains other functions which will run repeatedly. The first two lines of code check the GSM module for any available notification and print it on the serial monitor. Then it begins the main program by using the digitalRead(flame_sensor)  to check the state of the flame sensor D0 pin. If it is 1, it uses the digitalWrite() function to make both the buzzer and red_led LOW, thereby making sure they are turned off. But if the state of D0 is 0, it means that the flame sensor has detected fire, the Microcontroller immediately turns ON the buzzer and the Red LED using the digitalWrite() function. After which it runs the send_ multi_sms() function and then runs the make_multi_call().

The send_multi_sms() function and the make_multi_call() function gives the GSM module the ability to send messages and also make calls to 3 different numbers when the fire is detected. Both functions check the following variables “PHONE_1”, “PHONE_2”  and  “PHONE_3” if they contain phone numbers, then the GSM module will only send messages and also put a call to those numbers. These messages and calls are made using the following functions send_sms() and make_call() respectively, this is done by using the following commands “AT+CMGF=1\r”, “AT+CMGS=\””+phone+”\”\r”, ATD+ “+phone+”; “ATH”.

The last function boot() is called at the beginning of the program, this function delays the program to enable the GSM module to boot first.

THE LIMITATION BELOW IS NOT FOR THIS CHAPTER. IT SHOULD BE ADDED TO EITHER CHAPTER 1 OR CHAPTER 4 OF THIS PROJECT.

LIMITATIONS

  • This smart fire alarm system will only detect flames within a distance of 0 to 100cm.
  • This device will only work efficiently indoors. The reason is that the flame sensor works by detecting the presence of infrared radiation of wavelength within the range of 760 nm – 1100 nm emitted by flames. The sum is a ball of fire, so it emits infrared radiation that cuts across this wavelength, this will cause the device to malfunction outdoors. Thus, DO NOT TEST OR INSTALL THIS DEVICE IN AN OUTDOOR ENVIRONMENT.
  • Situations may occur where this device might detect fire, and sounds an alarm, but might not send a text message or call the phone number which it is programmed to. Please know that this error might not be due to software or hardware malfunction but due to an epileptic network. The smart property of this device depends solely on the external network provider. Thus, if there is a network failure, this device might not behave as expected.

Leave a Reply

Your email address will not be published. Required fields are marked *