This is an old revision of the document!
Security System with ESP32
author Dinu Diana-Gabriela ACES 2021
Page still under Construction…
1. Project Objective
The purpose of the project is to create a smart alarm system.
The security alarm does not provide audio feedback when movement is detected. The owner can turn the alarm on and off without physical access to the system, but rather via a web page. When turned on, if the security system detects movement it will notify the owner with an E-mail and will update the web page as well.
2. Project Description
The Security System consists of:
A web Server - it will allow the user to turn the system on and off, and to view the state of the system in real time (if motion is detected or not)
E-mail notifications - the user will receive E-mail notifications each time the security alarm is triggered by movement
Motion detection system - This is the physical part of the project, which will contain a PIR sensor which will detect the physical movement in the proximity of the system. The System will also contain 2 LEDs for visual feedback of the state of the system, one for the System State (on or off) and one for the motion sensor (if motion is detected or not)
3. Hardware Description
The hardware consists of:
ESP32 Development Board - The ESP32 Development Board is a system development board powered by ESP-WROOM-32 module. The ESP-WROOM-32 is a powerful and compact module that combines Wi-Fi and Bluetooth to support a wide range of applications that require wireless and internet connectivity [2]. The Wi-fi support, discreet size and price range made it perfect for this application.
PIR sensor - A Passive Infrared Sensor was used to detect the movement. It is an electronic sensor that measures infrared light coming from objects in its field of view. This type of sensor is widely used in security alarms. [1] The sensor picked has a delay of 8 seconds between changing its output. It can be powered from the 5V pin of the ESP32 board. It has an output voltage of 3.3V which can be read by the ESP32 board. It can detect movement at a maximum distance of 3m.
LEDs for visual feedback - the onboard LED of the ESP32 Development board is used for showing that the security system has the motion detection on or off. An external LED is also used to show if the Security System detected movement. In order to use the external LED, an additional resistor is also needed.
Besides the main components mentioned above, a breadboard and wires were also used in the making of this project.
insert board connection diagram…
4. Software Description
For software development, the Arduino IDE was used.
The main libraries used are:
WiFi.h - used to connect to the Wifi Network
ESP32_MailClient.h - library used to connect to a SMTP (Simple Mail Transfer Protocol) Server for sending emails.
SPIFFS.h - The SPIFFS (Serial Peripheral Interface Flash File System) library was used for saving images to the internal flash without using any external memories. SPIFFS is a file system used to split the flash of the ESP32 board in two regions, allowing the storage of files in the new region created.
time.h - used for getting accurate information on the time that passed between events and for getting local time information.
ESPAsyncWebServer.h and AsyncTCP.h - These libraries are used for creating the asynchronous Web Page. This allows for image usage and changing data on the page (for the motion feedback) without refreshing the page.
The main functionality of the page is sketched in the diagram below.
When the program is uploaded to the board, it will start the setup process.
During the setup it will initialize the board, the GPIO pins, it will connect to the Wi-fi Network and setup the web server. It will also get the local time, this is used for serial monitor debug.
After the setup is complete, regarding the Web server the following things will happen:
The Web page created at the board's IP address will monitor the switch state (which will be changed from the browser). On changing the switch state, the onboard LED (showing the Security System state - on or off) will change its state and an internal variable, which is used to block functionality when the Security System is off, will also change its value.
The Web Page will also request the state of the motion detection every 9.9seconds.
When refreshed the page will request the data from the board.
In parallel, the following things will happen, as per the diagram above:
The external LED is turned off if no previous motion was detected.
When an the state of the PIR sensor output changes to high, an interrupt will appear. This interrupt will start the detectsMovement() function. When this function is called the system knows there is motion detected.
This function checks that the Security System is turned ON before doing anything. If the system is OFF, nothing is done. If the system is on the external LED will be turned ON to signal movement. It will also connect to SMTP server given and will send an E-mail from teh borad's email to the user's email.
The program is set to wait for 10 seconds after a motion detection is made. This is partly because of the sensor delay of 8 seconds, and to limit the emails received. This time period can be increased. After these 10 seconds. the external LED is turned OFF and the cycle happens every time an interrupt (rising edge of the PIR sensor output) happens.
5. Issues and solutions
6. Conclusions
Bibliography