Engineers Garage

  • Electronic Projects & 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 WhatsApp-notifying home security system

By Nikhil Agnihotri April 2, 2023

A security alarm detects unauthorized entry into a home or building. In the past, these security devices simply triggered a loud siren when an intrusion was detected. As technology advanced, the systems were equipped with GSM modems to send an SMS alert to the home or building owner whenever an intrusion was detected. 

One drawback of the GSM-based alarm system is there’s no guarantee the message was delivered or received. For example, the GSM modem might be unable to connect to a cellular network and send the alert. So, users might not be notified that their home or building alarm system is activated. 

Fortunately, WiFi networks have become more widespread and reliable. It’s more than likely a home or office microcontroller can access the internet and web services to properly send a security alert message via SMS, email, WhatsApp, Telegram, or another communication app. 

In this project, we’ll design an ESP32-based security alarm that will send notifications to a WhatsApp number upon detection of an intrusion. The system requires no additional hardware to do so. Instead, it uses the Whatabot API to send the alert messages to the Whatsapp number. 

As a sophisticated WiFi development board, ESP32 easily connects to a WiFi network. The circuit for this project is so compact that it can be installed as a covert alarm, concealed anywhere in a home or office building. Or, if not used covertly, it can be integrated with a siren to activate an alarm upon detecting an intrusion.

Components required 

1. ESP32 x1
2. PIR sensor x1
3. LED x1
4. 330Ω resister
5. Connecting wires/Jumper wires

Circuit connections
It’s necessary to interface a PIR sensor with ESP32 to build this security system. The PIR sensor has three terminals: VDD, output, and ground. 

  • Connect the PIR sensor’s VDD and GND terminals with ESP32’s Vin and GND pins, respectively. 
  • Connect the PIR sensor’s output terminal to ESP32’s D13 pin. 
  • Connect an LED with ESP32’s D14 pin to visually indicate the alarm’s activation. Or, instead of the LED, the ESP32 pin can also be connected to an electronic siren. 

Whatabot API
We’ll use Whatabot API to send a security message to WhatsApp from ESP32 (learn how to do so here). Before going further, you must have a Whatabot API-activated account, a registered mobile number with the web service, and an API key for the account.

Arduino sketch
Once the circuit connections are complete, connect ESP32 to your computer and open Arduino IDE. you must have the ESP32 add-on installed to Arduino IDE or it will not recognize the ESP32 board. (To learn how to install the ESP32 add-on, here).

After ESP32 is successfully detected on Arduino IDE, select the port that ESP32 is connected with on your computer. Copy and paste the below sketch to the code editor. Save the code with a proper filename.

Remember, you must replace the SSID and NETWORK_KEY with the SSID and network key of your WiFi network in the code. Similarly, you will need to replace the MOBILE_NUMBER and API_KEY with your Whatabot-registered mobile number and API key in the code.

Lastly, compile and upload the code to ESP32.

How it works
The PIR sensor is interfaced with ESP32 to detect motion in a set area. If unauthorized movement is detected, the ESP32 signals an alarm. It also connects with an NTP server for the current timestamp. 

Next, it sends a WhatsApp message to the registered mobile number using Whatabot API. The WhatsApp alert contains the timestamp of the intrusion. Once the message is delivered, the alarm system rests for five minutes, so continuous notifications are not sent to the registered number. 

The code
The sketch begins by importing the WiFi.h, HTTPClient.h, UrlEncode.h, and time.h libraries. The WiFi.h connects with the WiFi network. The HTTPClient library makes the API call via an HTTP request. The UrlEncode library encodes the link for the API call. The time library processes the timestamp retrieved from the NTP server. 

The variables are declared to store the NTP server’s URL, GMT (offset in seconds), daylight (offset in seconds), and the current date (including time, hour, minutes, and seconds). 

The variables are then declared to store the WiFi network’s SSID and network key. Next, the variables are declared to store the registered mobile number and API key from the Whatabot web service. The variables are declared for the PIR sensor and the LED’s pin assignments. 

The user-defined function, sendWhatsappMessage(), is defined to deliver a text message that’s passed as an argument to the registered mobile number. This function stores the API URL as a variable. 

An object of the HTTPClient class is instantiated. The HTTPClient object makes the API call using the API URL. The http.addheader() function is called to add a header to the HTTP request. 

The response code is monitored by calling the http.GET() method. If the API call is successful, the WhatsApp message is delivered to the registered mobile number. If the call is unsuccessful, error messages are printed to the console (i.e., Arduino’s serial monitor). The HTTP request is terminated by calling the http.end() method. 

The user-defined function, currentLocalTime(), is defined to retrieve the current timestamp from the NTP server. This function instantiates a timestamp struct, retrieving the timestamp by calling the getLocalTime() method. The members of the timestamp struct are accessed and aggregated in a formatted string. The function updates the current_time variable with the formatted string containing the current timestamp.

In the setup() function, the baud rate for serial communication is set to 115200 bps to log the console messages. The pin connected to the PIR sensor’s output terminal is set as a digital input. The pin connected to the LED is set as zn digital output and is pulled LOW by default.

The WiFi network connection is initiated by calling the WiFi.begin() method. The local time settings with the NTP server are configured by calling the configTime() function.

In the loop() function, the state of the PIR sensor’s output pin is polled. If the output from the PIR sensor is HIGH, the alarm is activated by pushing the LED pin to HIGH.

The current timestamp is retrieved from the NTP server by calling the user-defined currentLocalTime() function. A WhatsApp message is sent to the registered mobile number, signaling an intrusion (with the timestamp) by calling the user-defined WhatsappMessage() send function. Otherwise, the alarm is silent.

Results

You may also like:


  • How to manage data on ESP32 for IoT projects

  • How to design a smartphone-operated door lock

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

  • Getting started with ESP8266 and ESP32 on Arduino IDE

  • How to send messages to WhatsApp or Telegram from ESP32

  • How to use ESP32’s sleep and wake-up modes in MicroPython

Filed Under: Electronic Projects, Sensors, Tutorials, Video
Tagged With: alarm, Arduino, arduinoide, ESP32, security, securitysystem, 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

  • Reducing "shoot-through" in offline Full Bridge SMPS?
  • High Side current sensing
  • How to simulate power electronics converter in PSpice?
  • Voltage mode pushpull is a nonsense SMPS?
  • Layout IRN reduction in Comparator

RSS Electro-Tech-Online.com Discussions

  • Back to the old BASIC days
  • Parts required for a personal project
  • PIC KIT 3 not able to program dsPIC
  • Failure of polypropylene motor-run capacitors
  • Siemens large industrial PLC parts

Featured – RPi Python Programming (27 Part)

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol
  • RPi Python Programming 26 – Interfacing ADXL345 accelerometer sensor with Raspberry Pi

Recent Articles

  • What is AWS IoT Core and when should you use it?
  • AC-DC power supply extends voltage range to 800 V DC
  • Infineon’s inductive sensor integrates coil system driver, signal conditioning circuits and DSP
  • Arm Cortex-M23 MCU delivers 87.5 µA/MHz active mode
  • STMicroelectronics releases automotive amplifiers with in-play open-load detection

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

  • Electronic Projects & 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