• nithya7rns

Sending Mobile Notification Alert for Fire using Raspberry Pi and Blynk - IoT

Updated: Dec 31, 2020

Flame/Fire sensor

Interfacing the hardware devices to our mobile and #portable devices is one of the most essential things today, even in our daily lives. Be it a small notification for our car being serviced and ready or a fire alert at home. This process of interfacing and receiving notifications can be a simple task to be easily carried out or a necessity. This basically tells us how #IoT has added to ease and monitor our day to day activities and avoid hazards.

Many such systems have been developed, like water level monitors in overhead tanks at homes, parking lot sensors in apartments to keep track of the vehicles coming in and out, and finally to the Home automation system itself. This article is going to give an idea of interfacing with a fire sensor and receive notifications to the mobile phone through the #Blynk App.

Hardware List

The following image shows all the components required for building the circuit.

Components of the circuit

  1. Raspberry Pi

Raspberry Pi chip

Unlike #Arduino, Raspberry Pi works with its own Operating System, Linux. So, Raspberry Pi can be called a single-board computer. It does not have any peripherals like a keyboard, mouse, etc. but works when connected to a system.

Features of Raspberry Pi:

In this project, the Raspberry Pi Model B/B+ can be used, which have a 1.2GHz/1.4GHz processor. It has inbuilt WiFi and #Bluetooth capabilities.

Buy the Raspberry Pi chip from here.

2. Flame sensor

Flame Sensor

The flame sensor has 4 pins namely A0, D0, GND, and Vcc. The A0 pin is the analog output pin for which an ADC (Analog-to-Digital Converter) needs to be used to get the desired output. The D0 pin is the Digital Output pin which directly gives the output in terms of 0 and 1.

The GND pin will be connected to the Ground pin of any other device that we will interface with. Vcc is the pin through which power in terms of Voltage will be provided to the #sensor to function accordingly. The sensor operates from 3.3V to 5V DC.

Buy Flame Sensor from here.

3. USB Cable

USB Cable

USB Cable is considered an Industry Standard for establishing connections between peripherals and #computers to transfer data between them.

Buy a USB cable from here.

4. Jumper Wires

Jumper Wires

Jumper wires establish a connection between the Raspberry Pi and the flame sensor. Both Male and Female wire configurations are required.

Buy Jumper Wires from here.

5. MicroSD card

MicroSD loaded with Raspbian OS

The MicroSD card used here needs to be loaded with Raspbian OS which is a zip file containing the code needed to run the #program on Raspberry Pi and allows interfacing between the hardware and software.

Buy a MicroSD Card from here.

Software Requirement

  1. Blynk App

Blynk App

It is an application installed in Andriod and iOS devices that allow interfacing hardware devices in real-time. It is an IoT platform that has free cloud storage. Blynk app allows creating a project dashboard, widgets, graphs, etc.

2. Raspberry Pi Imager

Raspberry Pi Imager (Logo)

The software is used to allow the interfacing of the hardware devices and #software applications. This software needs to be downloaded into the system for the Raspberry Pi Chip to be recognizable.

3. Python IDLE IDE

Python IDLE IDE (Logo)

The main software application is a #Python IDE for this device to work. The code is written in the notepad and saved with .py extension so that it becomes a python code file and can be interfaced with the device.

Circuit Diagram

Circuit Connections

The circuit connections for this device is simple. As stated above, the flame sensor has 4 pins amongst which we will be making use of three of them. They are the D0 (Digital Output), GND (Ground), and Vcc ( Voltage/Power Supply) pins.

The GND pin of the flame sensor is connected to the GND pin of the Raspberry Pi. The Vcc pin of the flame sensor is connected to the power supply pin of the chip. Finally, let's consider any one of the channel pins in Raspberry Pi to connect the D0 pin of the flame sensor. In our case, channel 4 is chosen.

The Raspberry Pi chip is then connected to the computer through the USB cable where the software is interfaced with the hardware device.


The code description is as follows.

import RPi.GPIO as GPIO

The import statement in the beginning imports the necessary library functions to recognize the functions used. The first statement imports the functions that are necessary for identifying the GPIO pins.

import time

The functions related to time such as delays, sleep time, bounce time, etc can be used after inheriting the 'time' library as in the above statement.

import BlynkLib

The 'BlynkLib' is included to allow the interfacing of the App and the code written to the circuit which is done using the functions associated like 'notify'.

channel = 4

This statement shows the declaration and initialization of a value to the variable channel which is nothing but the channel chosen for the output to be received from the flame sensor.


The above line of code sets the mode to GPIO of the Broadcom due to which the GPIO pins will be used for the transfer of data.

GPIO.setup(channel, GPIO.IN)

The next task is to assign the input mode of the Raspberry Pi chip as the input pin which takes in values from the flame sensor and the above statement executes the same.

BLYNK_AUTH = 'Your_Auth_Token'

This the code which will be used to recognize the user. On setting up the configuration of the Blynk App ( will be explained under the Working part of the article), an Authorisation Token will be sent to the Mail id provided. This value will be assigned to the variable BLYNK_AUTH.

blynk = BlynkLib.Blynk(BLYNK_AUTH)

The next step is to use the Library function which will take the Authorisation token to confirm the users and interface the device and the App.

def send_ntf(channel):
    blynk.notify('Fire at your place!!')

Then a function called 'send_ntf' is declared and defined. This user-defined function takes in a parameter for input which is the channel assigned, which in turn is the value provided from the pin of the flame sensor to that of the Raspberry Pi chip. The function sends a message/notification through the App to the mobile(device) interfaced. The notification will be 'Fire at your place!!'.

GPIO.add_event_detect(channel, GPIO.BOTH, bouncetime=300)

This line of code returns the values 0 or 1 based on the state of the sensor. It indicates whether the pin value is HIGH or LOW.

GPIO.add_event_detect(channel, GPIO.BOTH, bouncetime=300)

The next essential step is to send the notification when the value of the pin changes. The above statement does the same.

while True:

This is an infinite loop that should be executed until when we want the sensor to be working and sending the notifications to the Device connected through the Blynk App.


import RPi.GPIO as GPIO
import time
import BlynkLib
channel = 4
GPIO.setup(channel, GPIO.IN) 

BLYNK_AUTH = 'Your_Auth_Token'

blynk = BlynkLib.Blynk(BLYNK_AUTH)

def send_ntf(channel):
    blynk.notify('Fire at your place!!')

GPIO.add_event_detect(channel, GPIO.BOTH, bouncetime=300)  # let us know when the pin goes HIGH or LOW
GPIO.add_event_callback(channel, send_ntf)  # assign function to GPIO PIN, Run function on change
# infinite loop
while True:

For the complete code for this program, download the following document.

fire_mntf (Main)
Download TXT • 540B

Note: Please change the file extension to .py(python) file format before you upload the code to Raspberry Pi.


The following images show how the circuit looks when connected and assembled.

Connected, Unpowered circuit

Once the circuit connections are completed and the code is written in the IDE, connect the hardware device to the computer and interface the code to the hardware.

Python code file

The code is written in a notepad file and saved as a python file which creates the type of document required for the code execution.

Terminal window

After the file with the code is saved under the given extension, the SSH (Secure Socket Shell) #Terminal is opened.

Terminal Output

The saved file name is entered and is then opened in the terminal. The output of which is shown above.

The Hardware Powered up

By the time the terminal with the file and code is opened, the Blynk app must be opened and must be configured. That is the Notification must be enabled and the widget option must be chosen. The steps for which are shown in the project video given below.

The device in action

The explanation of the circuit building, code, and the work with the terminal is explained clearly in the video.

Video By - Sai Parimal

Flame sensor interfacing is one of the basic components of the home automation system. The scope of this project is huge and this is a basic circuit. The knowledge about building this circuit is essential for designing other big automation systems.

See also:

  • Facebook
  • YouTube
  • Instagram
  • LinkedIn
Contact Us
© Copyright - LearnElectronics 2021