Fire Alert to Gmail using Raspberry Pi - IoT

Updated: Sep 11, 2020

This article will teach you how to how to interface a Fire Alert to Gmail using Raspberry Pi. The fire sensor used in this circuit will help you detect any fire happening at your homes and send alerts to your email. This is a great way to get notified about incidents of fire, especially in sensitive industries dealing will inflammable materials and thus prevent the spread to a major extent.


1. Raspberry Pi: RaspberryPi is a single-board microcomputer which utilizes the SoC, DDR RAM memory, ethernet port, USB host, and micro HDMI on it. It provides the opportunity to interact with the outside world and using its processing power in a compact board at a low cost. In this application, we have used the Python IDE to simplify it.

2. Fire Sensor: A fire sensor is a #sensor that can detect a rise of almost 10 degrees temperature in the vicinity and alarm the authorized personnel through lighting or audio notification. This sensor also allows us to alarm using email, and we will focus on that part in this article.

3. SD Card for Raspberry Pi: We must use the right MicroSD for storing and installing the Pi in the system. It is always recommended to use a class-10 SDcard which is capable of storing all the information regarding the Raspberry Pi from installation to application.

4. Connecting Wires (Male-Female): As simple as it looks, these are used to connect ends without soldering. While male wired have protruding pins to plug into things, female jumpers are the ends that are used to plug into.

5. USB Cable for Raspberry Pi: This cord is used to temporarily connect the Raspberry Pi to the power supply.


The circuit is not very complicated and can be easily completed. The D0 can be connected to any of the GPIOs. This pin can be noted down and can be set up in the code accordingly.

For this particular project, we have used a voltage of 3.3V and is connected to the Vcc pin. We need to create a new e-mail id for the Raspberry Pi to receive e-mail notifications. But since there is a limitation of using all the features in the new, older email id is being used.

There are two major ways to detect fire; either using the onboard detection or using the fire sensors.

In the fire sensor, there are mainly two LEDs, one is the Power LED and the other is D0 LED. If the fire sensor detects affirmative, the D0 LED is turned ON, otherwise, it is OFF. the Power LED will always glow whenever there is a power supply from the sensor to the board.


The following are the commands to be run before executing the project.

Instead of this particular subject or message, any information can be passed according to the wish of an individual. Once these steps are completed, you can check the email whether you have received the notification.

Steps to follow before running the final code file

Step-1 -> sudo apt-get install ssmtp
Step-2 -> sudo apt-get install mailutils​
Step-3 -> sudo nano /etc/ssmtp/ssmtp.conf. Include the lines of code given below at the end of the file


	When this is done save the file (Ctrl+o) and close the file (Ctrl+x)

Step-4 -> Test it with the line of code given below in the terminal window

	echo "Hello Parimal" | mail -s "Testing..."

Download the code here and run it by converting it as a python code using the extension .py.

Commands to run before implementation
TX • 656B

Let us now understand how the code works.

The first command is about initializing the GPIO pins in the Raspberry Pi along with the fire sensor. The next libraries are for sending emails as well as setting up a delay.

The GPIO setup is fixed at pin 4 and the mail is triggered by the value that is received in this particular pin.

The respective e-mail ids are provided to the code along with the password for the Raspberry to send a notification. The subject and content in the mail are added later.

The next function is defined by how the Raspberry goes while alerting. It is initialized in the config function of how it logs into the system and warns about the fire at the user's place.

The header of the email includes, "to", "from" etc and is printed at the top of the email attached along with the text.

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

PASS= "Raspberry_Pi_Email_Password"

SUBJECT = 'Alert!'
TEXT = 'Your Raspberry Pi has detected fire at your place!'

def send_mail(channel): #the texting portion
    print "Sending text"
    server = smtplib.SMTP('')
    header = 'To: ' + GMAIL_USER_TO + '\n' + 'From: ' + GMAIL_USER_FROM
    header = header + '\n' + 'Subject: ' + SUBJECT + '\n'
    print header
    msg = header + '\n' + TEXT + '\n\n'
    print("Text sent")

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_mail)  # assign function to GPIO PIN, Run function on change
# infinite loop
while True:

Download the code here and run it by converting it as a python code using the extension .py.

fire_alert (Main)


When we check the hardware implementation, we see that there are mainly 4 pins in the fire sensor, namely A0, D0, Ground, and Vcc.

Once the hardware implementation is complete, we can open the directory in which the code is located and run the program to see how the Raspberry triggers an email about the fire.

Whenever a fire is detected, the D0 LED lights up to trigger the email about the same. The experiment shows the process where we bring in the fire to see how the email is sent.

First, the program is run and after the flame is brought nearby, the code shows an output saying "Text sent", which shows that the email has been received by the user.

In this particular experiment, the fire detected was at a close distance. This could be changed by adjusting the potentiometer value and enabling it to detect the fire from larger distances. Whenever a High or '1' is detected in the pin, the email is triggered by the Raspberry Pi.

Final Output and Working Video:

Video by: Sai Parimal

See Also:

  1. Interfacing an MPU6050 IMU Sensor with Raspberry Pi

  2. Interfacing Bluetooth HC-05 module with Raspberry Pi