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.
– 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
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.
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 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.
|const int analogInPin = A0;|
const int digitalInPin = 8;
const int ledPin = 13;
const int mq2Pin = A1;
int analogVal = analogRead(analogInPin);
boolean stat = digitalRead(digitalInPin);
if(stat == HIGH & val > 58)