Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Sensor Series
      • 3D Printing
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • 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
  • 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.

Submit a Guest Post

submit a guest post

EE TECH TOOLBOX

“ee
Tech Toolbox: Power Efficiency
Discover proven strategies for power conversion, wide bandgap devices, and motor control — balancing performance, cost, and sustainability across industrial, automotive, and IoT systems.

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.

  • Current sense transformer with Phase Shift Full Bridge
  • What is the frequency changing when I change the W?
  • PDKs setup for Virtuoso
  • Why do expensive synchronous rectifier controllers exist?
  • improving in delivering a signal from source to load

RSS Electro-Tech-Online.com Discussions

  • Manually actuate fuel tank selector solenoid
  • JLCPBC are using a different shipping company = less $$$$$$$$
  • Help please! BLDC driver circuit using the IR2136s and the STP80NF06 MOSFETS
  • need two ICs
  • MLT-8530 Buzzer on ESP32: Why Is the Sound Output Lower Than Expected?

Featured – Real Time Hardware Filter Design

  • Practical implementation of bandpass and band reject filters
  • Practical application of hardware filters with real-life examples
  • A filter design example
  • Types of filter responses
  • What are the two types of hardware filters?
  • What are hardware filters and their types?

Recent Articles

  • GigaDevices introduces 32-bit MCUs with integrated DSP and FPU support
  • Grinn introduces 8-core SBC supporting AI-ready embedded development
  • EPC’s 100 kHz BLDC inverter supports high-efficiency motion control
  • Melexis announces 5 W smart driver to supports sensorless FOC operation
  • STMicroelectronics’ motion sensor simplifies industrial IoT system design

EE ENGINEERING TRAINING DAYS

engineering
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • 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

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Sensor Series
      • 3D Printing
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • 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
  • Guest Post Guidelines
  • Advertise
  • Subscribe