Engineers Garage

  • Electronics Projects and Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

How to build a fire alarm with SMS and WhatsApp alerts

By Nikhil Agnihotri January 23, 2024

Fire alarms are critical in homes and buildings, mitigating fire risks and ensuring safety. These alarms aim to safeguard lives and property, providing a warning and initiating emergency procedures.

In this project, we’ll build a fire alarm system using ESP32, a flame sensor, and an MQ2 gas sensor. This device will trigger a buzzer and flash an LED if it detects smoke or any sign of fire. It will immediately send an SMS and a WhatsApp notification to the user.

Components required

  1. ESP32 x1
  2. Flame sensor x1
  3. MQ-2 gas sensor x1
  4. Buzzer x1
  5. LED x1
  6. 330Ω resistors x2
  7. Push button x1

Circuit connections
To build this fire alarm device, we’ll interface the flame sensor and MQ2 gas sensor with ESP32. The flame sensor detects smoke and fire and the MQ2 gas sensor detects flammable gases. We’ll use the DOIT ESP32 DevKit V1 as the ESP32. 

Let’s get started.

  • To interface the flame sensor, connect its out pin with ESP32’s GPIO36. 
  • To interface the MQ2 gas sensor, connect its digital output pin with ESP32’s GPIO39. 
  • Next, connect both sensors’ supply and ground pins with ESP32’s 3V3 and GND pins, respectively. 
  • Note: the MQ2 sensor’s analog output pin remains unconnected.  
  • Connect the buzzer to ESP32’s GPIO23. 
  • Connect the LED’s anode with ESP32’s GPIO22 and the cathode with ESP32’s 3.3V via the series resistor. 
  • Connect a push button with ESP32’s GPIO21.

Since ESP32 has built-in WiFi functionality, there’s no need to interface any Internet-enabling components. 

Here’s the circuit diagram of the ESP32-based fire alarm and warning system. 

Whatabot API
We’ll use Whatabot API to send a warning of a fire hazard via WhatsApp. Check out this project to learn how to use Whatabot API with ESP32.

Twilio API
We’ll use Twilio API to send an SMS alert of a fire hazard. Check out this project to learn how to use Twilio API with ESP32.

Arduino sketch

How it works
This alarm uses a flame sensor to detect fire and an MQ2 gas sensor to detect flammable gases. The gas sensor must be calibrated by adjusting the pot in its breakout board. This ensures it outputs a signal as soon it detects a specific concentration of flammable gases. 

Both sensors have a digital output and output a LOW signal if fire or gas is detected. The MQ2 gas sensor also has an analog output, but it’s not used for this project. 

When the fire alarm is powered ON, it reads signals from the flame and smoke sensors. If either sensor’s output is read as LOW, the fire alarm is triggered. The buzzer is switched ON, and the LED blinks. SMS and WhatsApp notifications about the fire hazard are sent to the user. The buzzer and LED remain ON until the push button is pressed to turn off the alarm.  

The code
The sketch begins by importing the WiFi.h, HTTPClient.h, UrlEncode.h, and twilio.hpp libraries. 

  • The WiFi.h library is required to connect with the WiFi access point. 
  • The HTTPClient.h is required to process the HTTP GET request. 
  • The UrlEncode.h is required to encode the URL according to the Web standards. 
  • The twilio library provides access to the functions required to send SMS messages through HTTP requests. 

The variables are declared to store the SSID and WiFi access point password. Variables are also declared to store the mobile number for the WhatsApp and API keys (received by registering the mobile number to Whatabot). 

For work with Twilio API, the variables must be declared for the account SID, authentication token, sender number (with country code), and receiver number (with country code). This application uses the same mobile number to send and receive an SMS alert.

Next, variables are declared for the pin assignments for the flame and gas sensors, the buzzer, the LED, and the push button. A variable is also declared to store the alarm’s status. 

In the setup() function, the pins connecting the flame and gas sensors and the push button are configured as digital inputs. The pins connecting the buzzer and LED are configured as digital outputs. 

The buzzer and LED are turned OFF by sending a HIGH signal. The baud rate is set to 115200 bps for sending debug messages to the console. The ESP32 is connected to WiFi via the user’s credentials. 

In the loop() function, ESP32 reads the flame and smoke sensors’ signals. If a LOW reading is received from either sensor, the alarm is raised via the raiseAlarm() function. The user-defined function, send_whatsapp_message() controls the notifications sent to the user’s WhatsApp number via the Whatabot API. The user-defined function, send_sms_alert, controls the SMS alerts sent to the user’s mobile number via Twilio API. These notifications are only sent if the fire alarm is set off.   

Results
Here are the console messages… 

Here’s a video demonstration of the operating fire alarm.

https://www.engineersgarage.com/wp-content/uploads/2024/01/P46-DV.mp4

You may also like:


  • How to build an app-controlled alarm mat

  • How to design an IoT-based smart alarm

  • How to manage data on ESP32 for IoT projects

  • How to design a smartphone-operated door lock

  • How to build a WhatsApp-notifying home security system

  • How to send SMS alerts from ESP32 without a GSM…

Filed Under: Electronic Projects, ESP8266, Video
Tagged With: alarm, electronicprojects, esp2866, ESP32, firealarm, sms, Whatsapp
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Transistor circuit in audio
  • MCU identification?
  • GanFet power switch starts burning after 20 sec
  • problem identifying pin purpose on PMA5-83-2WC+ amplifier
  • AC amplifier, transistor with bias network

RSS Electro-Tech-Online.com Discussions

  • stud mount Schottky diodes
  • LED circuit for 1/6 scale diorama
  • Can I use this charger in every country?
  • Electronic board faulty?!?
  • using a RTC in SF basic

Featured – Designing of Audio Amplifiers part 9 series

  • Basics of Audio Amplifier – 1/9
  • Designing 250 Milli Watt Audio Power Amplifier – 2/9
  • Designing 1 Watt Audio Power Amplifier – 3/9
  • Designing a Bass Boost Amplifier – 4/9
  • Designing a 6 Watt Car Audio Amplifier – 5/9
  • Design a low power amplifier for headphones- 6/9

Recent Articles

  • Fischer connector system adds ratchet locking system designed for 300g shock resistance
  • Littelfuse introduces tactile switch with enhanced bracket peg design for mounting strength
  • Infineon releases GaN switch with monolithic bidirectional design
  • Sienna Semiconductor data converters feature sample rates from 20 to 250 Msps
  • Delta’s 5,500 W power supplies achieve 97.5% energy efficiency for AI servers

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronics Projects and Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe