Lesson 33 Fire Alarm

Share for us
Share on facebook
Share on twitter
Share on pinterest
Share on whatsapp

Introduction

With the increasing use of fire and electricity in household, home fire accidents occur more and more frequently. Thus, fire alert plays a more important role in people’s life. In this lesson, we will use a gas sensor, a flame sensor and a passive buzzer module to assemble a fire alarm.

Components

– 1 * SunFounder Uno board

– 1 * USB data cable

– 1 * MQ-2 Gas sensor module

– 1 * Flame sensor module

– 1 * Passive Buzzer module

– Several jumper wires

Experimental Principle

Gas sensors can detect the concentration of smoke generated to warn of possible fires, when flame sensors can do the infrared rays emitted by fire. Detecting both smoke and flames, we can tell whether a fire’s happened. At the same time, the buzzer will beep to warn.

Experimental Procedures

Step 1: Build the circuit

Buzzer Connection: Connect pin S to D3 of Uno

MQ-2Gas Sensor Connection: Connect pin OUT to A1, VCC  to 5V, and GND to GND

Flame Sensor: Connect pin DO to D8, G to GND, and + to 5V

Step 2: Program (Please refer to the example code in LEARN -> Get Tutorial on our website)

Step 3: Compile

Step 4: Upload the sketch to SunFounder Uno

Now, ignite a lighter near the sensor and you can see the LED attached to pin 13 light up and the buzzer beeps.

Code

const int analogInPin = A0;
const int digitalInPin = 8;
const int ledPin = 13;
#
const int mq2Pin = A1;
void setup()
{
pinMode(digitalInPin,INPUT);
pinMode(ledPin,OUTPUT);
pinMode(3, OUTPUT);
Serial.begin(9600);
}void loop()
{
int val;
val=analogRead(mq2Pin);
Serial.println(val);
int analogVal = analogRead(analogInPin);
boolean stat = digitalRead(digitalInPin);
if(stat == HIGH & val > 58)
{
digitalWrite(ledPin,HIGH);
tone(3, 358);
delay(100);
}
else
{
digitalWrite(ledPin,LOW);
noTone(3);
}
}