Demo - fire detection

In this section, we'll develop a simple application to detect fire. In this case, we need two modules: flame sensor and buzzer. We will implement this demo using an Arduino board.

Our scenario is to read a fire-detection value from the flame sensor. If the sensor reading reaches a certain value, Arduino will turn on a buzzer device to generate a sound.

In general, the buzzer device has three pins: GND, VCC and Signal. We can connect the buzzer device to PWM pins on the Arduino. You can see the buzzer device here:

Let's start to implement the hardware wiring. Use the following connections:

  • Buzzer GND pin connected to Arduino GND pin
  • Buzzer VCC pin connected to Arduino 5V pin
  • Buzzer S (signal) pin connected to Arduino digital 9 pin
  • Flame sensor GND pin connected to Arduino GND pin
  • Flame sensor VCC pin connected to Arduino 3.3V pin
  • Flame sensor A0 pin connected to Arduino analog A0 pin

You can see the wiring diagram here:

For example, you can see my wiring implementation on the Arduino Leonardo here:

To access the buzzer device and generate sound, we can use the Tone object. You can learn more about it from https://www.arduino.cc/en/Reference/Tone.

The algorithm implementation is easy. Firstly, we open the Arduino software and write the following sketch program:

int flameSensor = A0;  
int buzzer = 9;  
int val = 0; 
 
void setup() {   
  pinMode(buzzer,OUTPUT); 
  Serial.begin(9600); 
} 
 
void loop() { 
  val = analogRead(flameSensor); 
  if(val > 50) { 
    Serial.print("Sensor Value = "); 
    Serial.print(val); 
    Serial.println(". Fire detected!!"); 
     
    tone(buzzer,1000);     
  } 
  else  
    noTone(buzzer); 
   
  delay(500); 
} 

Save this sketch as ArduinoFireDetection.

Now you build and upload your sketch program to your Arduino board. After it's uploaded, you can open the Serial Monitor tool from Arduino to see the program output.

Try to move your sensor next to a flame so you can see the sensor value on the Serial Monitor tool. You can see a sample program output here:

How it works

This program initializes all required pins in the setup() function.

int flameSensor = A0;  
int buzzer = 9;  
int val = 0; 
 
void setup() {   
  pinMode(buzzer,OUTPUT); 
  Serial.begin(9600); 
} 

In loop() function, we read the flame sensor value by calling the analogRead() function. In this case, we set the threshold value to 50. If the reading is greater than 50, we turn on our buzzer device by calling the tone() function:

void loop() { 
  val = analogRead(flameSensor); 
  if(val > 50) { 
    Serial.print("Sensor Value = "); 
    Serial.print(val); 
    Serial.println(". Fire detected!!"); 
     
    tone(buzzer,1000);     
  } 
  else  
    noTone(buzzer); 
   
  delay(500); 
} 

You can change the threshold value based on the results of your experiment.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.81.94