Home Fire Alarm System using Flame Sensor and LM35 Temperature Sensor

Overview:

Fire detection is very important in commercial buildings, factories, and most importantly houses. Luckily, a simple fire detection system can be made using the Arduino Upgraded Starter Kit.  In this tutorial, a flame sensor and LM35 temperature sensor along with other components like IR remote, buzzer and RGB module, will be interfaced with the Arduino to create a simple home fire alarm system.

 

Hardware:

 

Software:

  • Arduino IDE

 

Application Discussion

The fire detection system is a common project done using the Arduino. This project, compared to existing fire alarm systems, is much simpler and uses low-cost materials perfect for home use, and may not be as reliable as industrial grade ones. Nonetheless, the concept of early detection of fire is the same. In this home fire alarm system, the Arduino is interfaced with an LM35 temperature sensor and a generic flame sensor. An Infrared Receiver and Remote Control is also used to switch off or reset the alarm buzzer.

 

Flame Sensor

The flame sensor is a 2-pin sensor much like an LED with legs varying in length which specifies the polarity of the pins. This sensor is designed to detect and respond to the presence of fire or a flame. A burning flame will emit a certain level of IR (infrared) light which is not visible to the human eye but the flame sensor detects this and alerts the microcontroller.

LM35 Temperature Sensor

The LM35 is a temperature measuring device which produces an analog voltage proportional to the temperature. Thus, as temperature increases, the voltage output also increases. The sensor can only measure the temperature of its surroundings between 100 to 500 feet.

Important Note

It is important to make sure that the LM35 is handled properly. If the sensor is damaged, its output voltage will be inversely proportional to the temperature.

The LM35 can be damaged when:

  1. Pins are incorrectly set up (wrong connection)
  2. Exposed to static electricity

 

Infrared Receiver and Remote Control

Infrared (IR) is a widely used and inexpensive way to implement wireless control and communication. The typical setup of an infrared communication system makes use of an infrared receiver and transmitter. A much known example of an infrared communication is the TV remote. The Infrared transmitter looks just like a common LED, however, it produces light in the IR spectrum. This type of communication requires direct line of sight from the transmitter.

 

The infrared receiver is a photodiode that looks like this:

Or on a breakout board like this:

 

RGB 3-Color Module

The RGB 3-color module is an LED module which produces 3 colors: red, blue, and green with varying intensities. This is not however limited to the 3 colors, as it is possible to achieve different colors by mixing the three primary colors. The table below shows that for an 8-bit color intensity, we can produce different colors, with varying gradients. For 8-bits color: color intensity values range from 0 to 255, 0 as minimum and 255 as maximum.

COLOR

VALUES

R

G

B

Red

255

0

0

Green

0

255

0

Blue

0

0

255

Yellow

255

255

0

White

255

255

255

Cyan

0

255

255

Magenta

255

0

255

Raspberry

255

255

125

*The RGB pins must be connected to the PWM pins (~) of the Arduino in order to set the values.

 

Hardware Setup

 

Testing of LM35

To test the LM35, connect the pins accordingly:

LM35 PIN

ARDUINO PIN

Vcc

5V

Analog Out

A1

GND

GND

 

Upload the code below on the Arduino, this code can also be found on the Github repository here.


const int t_sensor= A1; 
float c_out; 

void setup() {
  pinMode(sensor,INPUT); 
  Serial.begin(9600);
}

void loop() {
  float reading=analogRead(t_sensor); 
  float vout= (reading*5000)/1024; //Converting to Celsius
  c_out= vout/10;
  
  Serial.print("Sensor Reading = ");
  Serial.print(reading);
  Serial.print("\t ");
  Serial.print("in Degrees C = ");
  Serial.print(temp);
  Serial.println();

  delay(1000);
}

 

Output

Let's try first a faulty LM35. The output of the faulty LM35, when exposed to heat, shows a visible decrease in voltage. This sensor was exposed to static electricity since it was packaged together with other components.

 

Now let's try a known good LM35. The voltage output below shows an increase in temperature when exposed to heat. This is the output we want. This sensor unit was packaged separately thus was not exposed to static electricity from other components.

 

IR Remote

The IR Remote keys produce a unique hexadecimal code which is modulated and sent to the IR receiver. In order for our code to work, it needs to be deciphered to have the microcontroller identify which key is pressed.

The deciphering of the codes require the IR receiver to be programmed with long sets of code. However, you can also opt in using libraries to code the IR Receiver. The library used in this tutorial can be found on the software setup section on this blogpost.

Note:

Different remotes send different codes for each key. Thus, it is important to determine the unique codes that your IR remote produces.

 

Upload the code below on the Arduino, this can also be found on the Github repository here.

This code makes use of the library mentioned in the software setup.


#include <IRremote.h>

const int IR_pin = 7;
IRrecv irrecv(IR_pin);
decode_results results;

void setup(){
  Serial.begin(9600); 
  irrecv.enableIRIn(); 
  irrecv.blink13(true); 
}

void loop(){
  if (irrecv.decode(&results)){ 
        Serial.println(results.value, HEX); 
        irrecv.resume(); 
        
  }
}

 

Once the code is uploaded, open the serial monitor and press the keys on your remote. The serial monitor will produce a unique code similar to the one shown below with every key pressed.

I have compiled the codes I got from the remote I used. The prefix “0x” is placed before the hex code to indicate the use of base sixteen (hexadecimal) instead of the default base ten.

KEY

CODE

CH-

0XFFA25D

CH

0xFF629D

CH+

0xFFE21D

 <<

0xFF22DD

>> 

0xFF02FD

 >||

0xFFC23D

-

0xFFE01F

+

0xFFA857

EQ

0xFF906F

 100+

0xFF9867

 200+

0xFFB04F

0

0XFF6897

1

0xFF30CF

2

0xFF18E7

3

0xFF7A85

4

0xFF10EF

5

0xFF38C7

6

0xFF5AA5

7

0xFF42BD

8

0xFF4AB5

9

0xFF52AD

 

 

Set-up the software

This project makes use of this library:

**Before including the library in the Arduino IDE we must first edit the file.

Since this project makes use of the buzzer and it is in conflict with the default timer setup in the IRremote library, we need to do the following steps first.

1. Extract IRRemote.ZIP.

  • Open the extracted folder, then navigate to these directories/folders:                        >> src >> private >> IRremoteBoardDefs.h                                    
  • Open the header file IRremoteBoardDefs.h using your favorite code or text editor. I am using Notepad++.

2. In line 195 you will find that define IR_USE_TIMER1 is commented out.

3. Simply uncomment the line define IR_USE_TIMER1 by removing the #  before it, and comment the line define IR_USE_TIMER2 by adding # before it. See below.

4.  Save changes and ZIP back the folder and name it IRremote.zip

5.  Add or include it to the Arduino IDE.

A guide on including libraries can be found here.

Finally, we can now upload the main code in our Arduino.

 

Code

The Arduino code can be found in Github here or you can copy the code below


#include <IRremote.h>

const int t_sensor = A1; //LM35 Pin const int f_sensor = A0; //Flame Sensor Pin int f_val = 0; float t_val; float c_out; const int IR_pin = 7; IRrecv irrecv(IR_pin); decode_results results; int buz = 8; int blu_pin = 9; //Analog Pin for RGB Module int red_pin = 10; //Analog Pin for RGB Module int grn_pin = 11; //Analog Pin for RGB Module int i=0; void setup() { irrecv.enableIRIn(); irrecv.blink13(true); //Arduino LED blinks when remote button is pressed pinMode(blu_pin,OUTPUT); pinMode(red_pin,OUTPUT); pinMode(grn_pin,OUTPUT); pinMode(buz,OUTPUT); pinMode(t_sensor,INPUT); pinMode(f_sensor,INPUT); Serial.begin(9600); } void loop() { RGB_color(0, 255, 0); // Green f_val = 0; c_out = 0; if (i==0){ //Checking Sensor Values f_val= analogRead(f_sensor); Serial.print("F sensor= "); Serial.print(f_val); Serial.print("\t"); t_val=analogRead(t_sensor); t_val=(t_val*5000)/1024; //Converting temp to Celsius c_out=(t_val)/10; Serial.print("T in DegC= "); Serial.print(c_out); Serial.println(); delay(1000); } if (f_val < 890 || c_out>= 75) { emergencyAlert(); } if (f_val < 890 && c_out>= 75) { emergencyAlert(); } } void emergencyAlert(){ //When sensors are triggered i=1; RGB_color(255, 0, 0); // Red tone(buz,500,400); delay(500); remoteCheck(); } void remoteCheck(){ //Check if remote is being operated if (irrecv.decode(&results)) { Serial.println(results.value, HEX); if (results.value == 0xFF30CF && i==1 ) { //Turn off buzzer RGB_color(0, 0, 255); // Blue noTone (buz); delay(10000); //Wait for 10 seconds before restart i=0; } if (results.value == 0xFF18E7) { //RESET immediately RGB_color(255, 255, 0); // Yellow delay(1000); i=0; } irrecv.resume(); // Receive the next value } } void RGB_color(int red_light_value, int green_light_value, int blue_light_value) { //RGB color set analogWrite(red_pin, red_light_value); analogWrite(grn_pin, green_light_value); analogWrite(blu_pin, blue_light_value); }

 

Code Breakdown

  • irrecv.blink13(true)
    – Sets the Arduino LED to blink when IR signal is received from the transmitter (remote).

  • pinMode(pin,mode) 
    – Configures the identified pin to behave as an input or an output.

  • analogRead
    – Reads input analog value and converts to digital; digital value can range from 0-1023 (10 bits)

  • Serial.begin(9600)
    –  tells the Arduino to get ready to exchange messages with the Serial Monitor at a data rate of 9600 bits per second

  • Serial.println(text)
    – Prints text and adds a new line to the serial monitor.

  • digitalWrite(pin, value)
    – This sets the designated pin to a HIGH(5V) or LOW(0V) value.

  • tone(pin, frequency)
    – to play a tone on the buzzer at the specified pin with the specified audible frequency

  • noTone(pin)
    – stops the generation of square wave created by tone()

  • irrecv.resume()
    – this allows the remote to receive the next value.

  • emergencyAlert()
    – This function is called when the set threshold values for the flame and temperature sensors are triggered. This function relies on the if statement it is called from. This results to the RGB LED turning RED to indicate an alert and also triggers the buzzer.

  • remoteCheck()
    – This function is called once the emergencyAlert is triggered. This function will operate the IR receiver to check if an IR signal is being transmitted from the remote. This makes use of the remote codes discussed in the hardware setup.

  • RGB_color(int red_light_value, int green_light_value, int blue_light_value)
    – This function is called when we set a certain color on the RGB 3-color module . This creates a shorter code when setting up which color you want to display on the module. The values for different colors can be found on the application discussion.

 

Video Output

 

Conclusion

This project shows how to interface several components and modules into the Arduino to create a fire alarm system. In this case we have interfaced an analog temperature sensor (LM35), a flame sensor, an IR receiver and transmitter (remote), a buzzer, and an RGB LED module.

This system is quite beneficial for small-scale use since the sensors are only limited to a certain distance. However, this project can still be improved by replacing it with sensors capable of sensing longer distances. A home fire alarm system is not limited to only a buzzer, you can upscale this project by adding a GSM module to send you SMS (text) alerts whenever it is triggered.

For more fun projects and tutorials visit Createlabz here.

 

Reference

https://arduinomodules.info/ky-016-rgb-full-color-led-module/

https://arduinoplusplus.wordpress.com/2018/02/04/reading-lm34-lm35-lm335-lm3x-temperature-sensors-accurately/

ArduinoArduino starter kitArduino unoBuzzerColor ledFlame sensorIr receiverLm35RemoteRgbRgm moduleTemperature sensor

Leave a comment

All comments are moderated before being published