Arduino Projects

Forest Fire Detection System using Arduino and Image Processing vb.net

Forest Fire Detection System Project Description:

 

Forest Fire Detection System- This project is based on image processing based forest fire detection along with an email notification. It concentrates in particular on systems that use image and video processing for converting visual data into a form that can be understood by the computer program.

In this project the image processing is done using visual basic dot net “VB.NET” 2010 express edition using emgucv. Emgu CV is a cross platform .Net wrapper to the OpenCV image processing library. Allowing OpenCV functions to be called from .NET compatible languages such as C#, VB, VC++, IronPython etc. The wrapper can be compiled in Mono and run on Windows, Linux, Mac OS X, iPhone, iPad and Android devices.

In this project, a special computer application is designed in Visual Basic “VB.NET”.  This designed application is capable of detecting the fire and displaying the temperature in Centigrade in real-time. There is a certain threshold value set for the temperature Sensor defined in the Arduino programming. This threshold value can be adjusted as per the requirement. The K-type thermocouple is used to monitoring the temperature. This temperature sensor is capable of measuring the temperature greater than 1000C which is perfect for this project.

As you know using the image processing there is a high chance of the false detection, to overcome the problem of false detection, I used a temperature sensor with the Arduino which monitors the temperature in that particular area. As you know temperature rises due to the fire. So, this temperature monitoring system will work as the feedback for the fire detection application.

So, a notification email will only be sent if the fire is detected and the temperature has crossed a predefined value. For the email notification both the conditions should satisfy. If any of the two is missing, it will be taken as the false data.


Amazon Purchase Links:

MAX6675 k type thermocouple and driver:

12v Adaptor:

Arduino Uno

Arduino Nano

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

DISCLAIMER:

Please Note: these are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!



How to create an XML file for Fire Detection:

This is my 6th tutorial on image processing using Arduino and VB.NET. In my previous tutorial on the eye pupil tracking system, I explained all the steps on how to train an XML file and then how to use that XML file in the VB.NET application for detecting the human eye. The same technique is used in this project as well. I used the following images to train my own XML file.

Forest Fire Detection System

You need to watch this tutorial if you want to learn how to create your own XML file for fire detection.

You can use the fire XML file which I created. But I recommend you should try yourself. If you learned this method of creating the XML files, you will be able to detect and track any object.

Download fire XML file: fire


K type thermocouple connection with Arduino Uno:

Forest Fire Detection System

As you can see the circuit diagram is very simple. The Max6675 breakout board is used with the K type thermocouple. The VCC of the Max6675 is connected with the Arduino’s 5 volts. The ground pin of the Max6675 is connected with the Arduino’s ground. The SCK pin of the Max6675 breakout board is connected with the pin number 6 of the Arduino Uno. The CS pin of the Max6675 is connected with the Arduino’s pin number 5 and the last pin SO of the Max6675 breakout board is connected with the Arduino’s pin number 4.

The +VE and GND wires of the K type thermocouple will be connected with the +VE and GND contacts of the Max6675 breakout board.


Forest fire detection system Arduino Programming:

Before you start the programming, first of all, make sure that you download the max6675 library. This library can be downloaded by clicking on the download button below.

Download Libraries

#include "max6675.h"

int thermoDO = 4; // so
int thermoCS = 5; //
int thermoCLK = 6; // sck

 
float temp1 = 0;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);

void setup() {

  Serial.begin(9600); 

  // wait for MAX chip to stabilize, 500 milli seconds equal to a half second
  delay(500); 
}

void loop() {

  // Serial.println(thermocouple.readFahrenheit());
 temp1 = thermocouple.readCelsius();

     Serial.println(temp1);               
 // adjust the following conditions according to the temperature we want to set .
        if(temp1 < 40   )
        {
          Serial.println("normal"); 
        delay(1000);
        } 
        if(temp1 > 60)
        {
          Serial.println("fire");
           delay(1000);
        } else 
        delay(500);
}

Forest Fire Arduino Program Explanation:

You need the following library to use the K type thermocouple and max6675.

#include “max6675.h”

Following are the Arduino’s pins defined for the D0, CS, and CLK. These are the pins of the max6675 breakout board.

int thermoDO = 4; // so

int thermoCS = 5; //

int thermoCLK = 6; // sck

A variable temp1 of the type float is used to store the temperature.

float temp1 = 0;

MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);

void setup() {

For the Serial communication with the Computer or Laptop, you need to specify the baud rate. In my case, I selected 9600. Make sure you use the same baud rate in the designed fire detection application, otherwise the project won’t work.

Serial.begin(9600);

// wait for MAX chip to stabilize, 500 milli seconds equal to a half second

delay(500);

}

void loop() {

The following line reads the temperature and store the value in temp1.

temp1 = thermocouple.readCelsius();

Using the serial.println function the temperature value is sent serially to the computer fire detection application.

Serial.println(temp1);

// adjust the following conditions according to the temperature you want to set .

if(temp1 < 40   )

{

Serial.println(“normal”);

delay(1000);

}

if(temp1 > 60)

{

Serial.println(“fire”);

delay(1000);

} else

delay(500);

}


VB.NET Fire Detection Application:

Forest Fire Detection System

The form1 has a picturebox1, one button with the caption Button1, Six labels, a checkbox with the caption fire sensor data and a text box. A total of 6 timers are used in the form and a serial port. This Serial Port is important for the communication between the Arduino and computer applications. This is the same application I used in the human face recognition based entrance door lock control system.

Read all of my previous 5 articles on the image processing, because these are using the same concept and I have already explained the extreme basics, so that’s why In this article I am giving you only the references.


Image Processing Forest Fire Detection Application Programming:

Before you start the programming, first of all, make sure that you download and install the emgucv. The version of the emgucv used is already explained in my previous tutorials.

' libraries
Imports System.Runtime.InteropServices
Imports System.Threading
Imports System.IO
Imports System.Net
Imports System.Net.Mail
Imports System.Net.NetworkCredential
Imports System.Reflection
Imports System.Text
Imports Microsoft.Win32

Imports System.IO.Ports

Imports Emgu.CV
Imports Emgu.CV.Util

Imports Emgu.CV.Structure
Imports System.Diagnostics


Public Class Form1
    Dim firecount As Integer = 0
    Dim fireflag As Integer = 0

    Dim eyesdetected As Integer
    Dim firedetected As Integer
    Dim eyesclosedtime As Integer
    Dim eyesclosedtimelong As Integer
    Dim web As Capture = New Capture


    ' thread-safe calling for thread_hide
    Delegate Sub Change()


    Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Int32, ByVal dwReserved As Int32) As Boolean


    Delegate Sub SetTextCallback(ByVal [text] As String)


    Private Sub frmKeyRogger_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        If Me.WindowState = FormWindowState.Minimized Then
            Me.Hide()
        End If
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        fire()



    End Sub


    Private Sub wait(ByVal interval As Integer)
        Dim sw As New Stopwatch
        sw.Start()
        Do While sw.ElapsedMilliseconds < interval
            ' Allows UI to remain responsive
            Application.DoEvents()
        Loop
        sw.Stop()
    End Sub

    Sub playbackgroundsoundsleepy()
        My.Computer.Audio.Play(My.Resources.sleepy, AudioPlayMode.WaitToComplete)

    End Sub

    Sub playbackgroundsoundsevere()
        My.Computer.Audio.Play(My.Resources.severe, AudioPlayMode.WaitToComplete)

    End Sub


    Sub fire()
        Dim photo As Image(Of Bgr, Byte)
        Dim currentCenter As New Point()
        photo = web.RetrieveBgrFrame

        Dim carsdetection As New CascadeClassifier("C:\data\haarcascades\fire.xml") ' this one is for the face detection  haarcascade_frontalface_default
        firedetected = 0


        Try
            Dim image As Image(Of Gray, Byte) = photo.Convert(Of Gray, Byte)()

            For Each face As Rectangle In carsdetection.DetectMultiScale(image, 1.1, 8, Size.Empty, Size.Empty) ' default 1.1, 8  ( while best values are 1.2 and 17 after checking)

                photo.Draw(face, New Bgr(Color.Red), 10) ' if used negative number then the rectangle is filled



                currentCenter.X = CInt(CDbl(face.X + face.X + face.Width) / 2.0)
                currentCenter.Y = CInt(CDbl(face.Y + face.Y + face.Height) / 2.0)

                Label1.Text = (currentCenter.X).ToString
                Label2.Text = (currentCenter.Y).ToString

                firedetected = 1  ' we are storing 1 if eyes are detected.


            Next

            PictureBox1.Image = photo.ToBitmap


        Catch ex As Exception

        End Try

        If firedetected = 1 Then
            Label4.Text = " fire detected"


        Else
            Label4.Text = " no fire"
            firedetected = 0

        End If


    End Sub




    Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
        If InStr(txtOutput.Text, "fire") Then

            CheckBox2.Checked = True
            CheckBox2.Text = "Fire"
        End If
        If InStr(txtOutput.Text, "no") Then

            CheckBox2.Checked = False
            CheckBox2.Text = "No Fire"
        End If
    End Sub

    Private Sub Timer5_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer5.Tick
        If ((CheckBox2.Checked = True) And (firedetected = 1)) Then

            Dim smtp As New SmtpClient
            Dim message As New MailMessage
            Dim username As String
            Dim password As String
            Dim destination As String
            Dim subject As String
            Dim lngFlags As Integer

            username = "fireforrest392@gmail.com"
            password = "electroniclinic"
            destination = "fire@gmail.com"
            subject = "Fire detected"
            smtp.Host = "smtp.gmail.com"
            smtp.EnableSsl = True
            smtp.Port = 587
            smtp.Credentials = New Net.NetworkCredential(username, password)

            message.To.Add(destination)
            message.From = New MailAddress(username)
            message.Subject = subject
            message.Body = txtOutput.Text
            If InternetGetConnectedState(lngFlags, 0) Then ' checks if internet connection is available or not

                smtp.Send(message)
                txtOutput.Text = ""
                CheckBox2.Checked = False


            Else
                txtOutput.Text = txtOutput.Text + "" + vbNewLine + " net connection not available" + vbNewLine + ""


            End If


        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SerialPort1.Close()
        SerialPort1.PortName = "com5"
        SerialPort1.BaudRate = "9600"
        SerialPort1.DataBits = 8
        SerialPort1.Parity = Parity.None
        SerialPort1.StopBits = StopBits.One
        SerialPort1.Handshake = Handshake.None
        SerialPort1.Encoding = System.Text.Encoding.Default
        SerialPort1.Open()

    End Sub

    Private Sub DataReceived(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
        Try
            Dim mydata As String = ""
            mydata = SerialPort1.ReadExisting()

            If txtOutput.InvokeRequired Then
                txtOutput.Invoke(DirectCast(Sub() txtOutput.Text &= mydata, MethodInvoker))
            Else
                txtOutput.Text &= mydata
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub Timer6_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer6.Tick
        txtOutput.Text = ""

    End Sub

End Class


Forest fire detection system Report / Thesis:

The complete thesis of the forest fire detection system based on the image processing can be downloaded by clicking on the following download button.

Download thesis:

watch video tutorial:

Related Articles:

Related Arduino and vb.net Image Processing Projects:

Eye pupil Tracking

VB.Net Image Processing 

Arduino Image Processing CCTV

OCR Recognition using VB.net

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Leave a Reply

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

Back to top button