Iot security surveillance car with telegram integration Iot security surveillance car with telegram integration Iot security surveillance car with telegram integration
Trang 1INTERNATIONAL SCHOOL VIETNAM NATIONAL UNIVERSITY, HANOI
GRADUATION THESIS
Title: IoT Security Surveillance Car with Telegram Integration
Student Name: Trinh Le Hoang
Student ID: 20070833 Supervisor: Dr Kim Dinh Thai
Hanoi, 2025
Trang 2I would like to express my deepest gratitude to Dr Kim Dinh Thai for their ceptional mentorship and unwavering support throughout this project Dr Thai’sinsightful guidance and detailed feedback on both technical and methodological as-pects have greatly enhanced the quality and depth of my research Their dedicationand encouragement have been an invaluable source of inspiration, motivating me tostrive for excellence
ex-I am also profoundly grateful to Vietnam National University, Hanoi – ex-tional School, for providing the necessary resources and supportive environment tosuccessfully complete this graduation project The institution’s commitment to foster-ing academic growth has been instrumental in helping me achieve the objectives of mystudy
Interna-Although every effort has been made to ensure the thoroughness and accuracy ofthis work, I humbly acknowledge that there may still be areas for improvement Iwarmly welcome constructive feedback and suggestions from readers, which will helprefine and advance this research further
Sincerely thank,Trinh Le Hoang
Trang 3pan-The research involves detailed system analysis and design, focusing on both ware and software integration to achieve seamless functionality Key components in-clude an ESP32 CAM module for video processing and streaming, DC and servo motorsfor precise movement and camera control, and a Telegram Bot interface for user-friendlyremote interaction.
hard-Results demonstrate the system’s strong performance in real-time video sion with minimal latency, responsive command execution, and adaptability acrossdiverse environments Challenges such as WiFi range limitations and power consump-tion are addressed with proposed solutions, including external antennas and energyoptimization techniques
transmis-This project highlights the potential of low-cost IoT technologies in creating novative solutions for dynamic and practical applications Future improvements aim
in-to incorporate AI-driven object detection and advanced energy harvesting in-to furtherenhance system capabilities
Trang 4List of Tables
3.1 Motor Control Test Results 40
3.2 Camera Movement Test Results 40
3.3 Video Streaming Test Results 42
3.4 Command Execution Test Results 43
3.5 Motion Detection Test Results 44
3.6 Compact Performance Overview of Tested Functionalities 46
Trang 5List of Figures
1.1 Global IoT Growth by Communication Solution (2019-2030) 1
2.1 IoT Layer Structure 11
2.2 System Design Diagram 14
2.3 Motor and Servo System with ESP32-Cam 16
2.4 L298N to DC motor 18
2.5 System Flowchart 19
2.6 ESP32-CAM WiFi and Telegram Integration 21
2.7 How PIR Senor work 23
2.8 ESP32-CAM PIR Motion + Telegram Notifications Flowchart 25
2.9 Create Telegram Bot 28
2.10 ESP32 CAM Car System Wiring Diagram 30
2.11 ESP32-CAM Module Setup 33
2.12 ESP32-CAM Code Libraries 34
2.13 Connect to ESP32-CAM Wifi 36
3.1 ESP32 CAM Car Control Interface 41
3.2 Telegram Bot Interface for ESP32 CAM Car 43
3.3 Bot responds with appropriate error messages 44
3.4 Remote-Controlled Robot Car in Action 47
5.1 ESP32-CAM Specifications 55
5.2 Camera Specifications 56
5.3 L298N 58
5.4 HC-SR501 PIR Motion Sensor 60
5.5 LM2596 63
5.6 2V to 5V Power Conversion with LM2596 65
5.7 Servo SG90 66
5.8 Buzzer 68
5.9 DC Gear Motor with Wheels 69
Trang 61.1 Project Motivation 1
1.2 Objectives of the Project 2
1.3 Scope of Research 3
1.3.1 Target Customers 3
1.3.2 Methodology 4
1.3.3 Evaluation Criteria 5
1.4 Literature Review 6
2 Analysis, Design, and System Deployment 10 2.1 System Analysis 10
2.2 System Design 11
2.2.1 IoT Layers 11
2.2.2 Hardware Design 14
2.2.3 Deployment 30
3 Test and Evaluation 38 3.1 Functional Testing 38
3.2 Performance Testing 39
3.3 Evaluation 46
4 Conclusion and Future Development 48 4.1 Conclusion 48
4.1.1 Achievements 48
4.1.2 Limitations 49
4.2 Future Development 50
Trang 75 Appendix 54
5.0.1 Hardware Components 54
Trang 8Chapter 1 Project Overview
The development of this project is driven by the increasing demand for flexible, effective, and advanced surveillance systems, fueled by the rapid evolution of IoT (In-ternet of Things) and robotics technologies Traditional surveillance systems, whilereliable in fixed scenarios, present several limitations that are becoming more apparent
cost-in modern security challenges
Figure 1.1: Global IoT Growth by Communication Solution (2019-2030)
Limitations of Traditional Surveillance Systems
1 High Cost and Accessibility Issues:
• Conventional surveillance systems require substantial investment in ture, such as wired networks, fixed cameras, and monitoring equipment
infrastruc-• These costs make it difficult for smaller organizations, households, or low-budgetprojects to adopt such systems effectively
2 Immobility and Static Coverage:
Trang 9• Fixed surveillance cameras are stationary, leading to blind spots in coverage andthe inability to monitor dynamic environments or areas outside their fixed field of view.
• These systems lack the adaptability required for tasks such as tracking objects ormonitoring large or irregular spaces
4 Growing Need for Remote and Automated Monitoring:
• In today’s fast-paced and distributed environments, there is a clear demand forsystems that allow users to monitor and control security remotely
• Traditional systems often lack the integration of user-friendly remote-control terfaces, limiting their usability
in-Trends Driving IoT and Robotics in Surveillance
1 Adoption of IoT in Security Applications:
• IoT-based surveillance solutions enable the integration of connected devices forreal-time monitoring, communication, and control
• These systems reduce infrastructure costs while enhancing flexibility and bility
scala-2 Advancements in Robotics for Mobility:
• Robotic systems, such as mobile surveillance units, provide adaptable coverage
by physically moving to required areas
• Mobility ensures better visibility, reduces blind spots, and allows dynamic trolling in complex environments
pa-3 Real-Time Communication Technologies:
• Platforms such as Telegram offer secure and user-friendly interfaces for real-timeinteraction and control
• Integration with IoT devices ensures seamless operation, alert notifications, andquick decision-making for users
This project was conceived to address these challenges by integrating IoT, robotics,and real-time communication technologies into a mobile surveillance solution Theobjectives of the project are:
1 Provide Real-Time Surveillance:
• Enable real-time video streaming for users to monitor activities directly from theirdevices
Trang 102 Enable Mobility and Adaptability:
• Develop a mobile surveillance car capable of moving across dynamic environments
to provide flexible coverage and eliminate blind spots
3 Integrate Motion Detection and Alerts:
• Include a PIR motion sensor to detect movement and send instant notificationswith images to the user via Telegram
4 Offer Remote Control via Telegram:
• Use a Telegram bot as the main control interface, allowing users to send commands(e.g., move the car, adjust the camera, take pictures) and receive updates in real time
5 Ensure Cost-Effectiveness and Ease of Use:
• Design a low-cost, portable system suitable for personal, small business, andeducational applications
o Affordable and easy-to-use systems to monitor their properties
o Real-time video streaming and motion alerts to respond to potential threatsquickly
o Flexibility to move the surveillance system to different areas as needed
• Value Proposition: A low-cost, user-friendly system that enhances home securitywithout the high expense of traditional surveillance setups
o Real-time monitoring to deter theft and track activities within their premises
• Value Proposition: A scalable and portable surveillance system that providesreal-time security for small businesses at an accessible price point
Trang 113 Educational Institutions:
• Target Audience: Schools, universities, and training centers interested in teachingand demonstrating IoT, robotics, and smart technologies
• Key Needs:
o A practical, hands-on demonstration tool for IoT and robotics concepts
o Simple and accessible systems for students to learn about programming, sensorintegration, and system control
• Value Proposition: A versatile system that serves as both a learning resource and
a functional surveillance solution
o A project platform for enhancing technical skills in IoT and robotics
• Value Proposition: An open, adaptable system ideal for personal or experimentalprojects
The project is carried out in a systematic approach to ensure an efficient and reliabledevelopment process It includes the following steps:
1 Hardware Selection:
• Carefully chosen components to balance cost, performance, and functionality:
o ESP32-CAM: Central controller for video streaming and system management
o L298N Motor Driver and DC Motors: Enable precise movement for mobility
o PIR Motion Sensor: Detects motion and triggers alerts
o SG90 Servos: Provide pan-tilt functionality for dynamic camera control
o Power System: A 12V battery with an LM2596 voltage regulator for stable ation
Trang 12o Configuring the LM2596 regulator to ensure a stable 5V output for critical ponents.
com-3 Software Development:
• Writing and testing code to control the system’s operations:
o Programming the ESP32-CAM for tasks like movement control, motion detection,and video streaming
o Setting up a local web server for real-time video access
o Developing a Telegram bot to receive commands (e.g., movement, camera control)and send notifications
4 Testing and Optimization:
• Conducting real-world tests to ensure the system meets functional and mance requirements:
perfor-o Evaluating latency, mperfor-otiperfor-on detectiperfor-on accuracy, and mperfor-obility perfperfor-ormance
o Identifying and resolving hardware or software issues to enhance reliability
o Optimizing power consumption for longer operational times
1.3.3 Evaluation Criteria
The system’s effectiveness and practicality are assessed using the following criteria:
1 Video Streaming Performance:
• The system should provide clear and stable video streaming with minimal latency
• Latency must remain below 0.3 seconds to ensure a seamless viewing experience,even in dynamic scenarios
2 Motion Detection Accuracy:
• The PIR sensor must accurately detect motion in the defined range of 3-7 meters
• Alerts and captured images must be sent to Telegram within 2 seconds to ensuretimely responses to security events
Trang 134 Remote Control Features:
• All Telegram commands, including photo capture, motion detection toggle, andflash control, must execute within 200ms
• The system must maintain a stable connection to Telegram under standard Wi-Ficonditions
5 Energy Efficiency:
• The system must operate for at least 2 hours continuously using the 12V battery
• Power consumption should be optimized to maximize battery life and minimizedowntime
ex-7 Flexibility and Scalability:
• The system should adapt to different environments and integrate with variousvehicle types
• Its modular design should allow for future upgrades or the addition of advancedfeatures like GPS or AI
8 Security and Reliability:
• Data must be securely transmitted and stored to prevent unauthorized access
• The system must operate reliably under diverse conditions to build user dence
Overview of IoT in Surveillance Systems
The Internet of Things (IoT) has transformed the landscape of surveillance and itoring systems by enabling real-time connectivity, remote control, and data-drivenintelligence Numerous studies have explored various aspects of IoT-based securitysystems, paving the way for innovative solutions to modern challenges
Trang 14mon-1 IoT-Powered Surveillance Systems:
• Smith and John (2020) provided a comprehensive analysis of IoT applications insurveillance, emphasizing real-time monitoring and automation Their research high-lighted the role of wireless sensors and cloud-based platforms in enhancing systemflexibility and scalability
• Jain et al (2021) investigated IoT-enabled smart home security systems usinglow-power devices They concluded that IoT integration significantly reduces costs andimproves response times compared to traditional systems
2 ESP32-CAM for Real-Time Video Streaming:
• Research by Hassan and Ahmed (2020) focused on the ESP32-CAM module,highlighting its capabilities in capturing and streaming live video over WiFi networks.Their findings emphasized its affordability and compact size but pointed out challengessuch as heat generation during prolonged usage
• Nguyen et al (2022) optimized ESP32-CAM performance by adjusting JPEGquality and frame size parameters Their study demonstrated that a balance betweenvideo quality and network bandwidth is critical for stable operation
3 Motion Detection with PIR Sensors:
• Kumar and Singh (2019) evaluated passive infrared (PIR) sensors for motiondetection in security applications Their work demonstrated the high reliability of PIRsensors in detecting human presence while maintaining low power consumption
• Roberts (2020) integrated PIR sensors with IoT systems, discussing how ing motion detection with cloud-based alerts can improve response times in emergencyscenarios
combin-4 Motor Drivers in Robotic Applications:
• Tran and Le (2021) studied the efficiency of the L298N motor driver in controlling
DC motors for robotic cars While the driver proved reliable for basic applications, thestudy noted its energy inefficiency compared to newer alternatives like the DRV8833driver
• Sharma and Gupta (2022) implemented motor control algorithms to enhancethe maneuverability of IoT-based surveillance robots Their findings underscored theimportance of precise speed control and directionality in improving navigation
5 Integration of Telegram Bot in IoT Systems:
• Telegram API Documentation (2023) provided extensive details on integratingTelegram Bot with IoT devices The research highlighted the simplicity of setting
Trang 15up commands and real-time messaging, making Telegram a popular choice for remotemonitoring systems.
• Patel et al (2022) successfully deployed a Telegram Bot interface for an IoT smartirrigation system Their work demonstrated how bots can simplify user interactionwhile maintaining robust security features like chat ID validation
6 Power Management with LM2596:
• Nguyen and Hoang (2022) analyzed the use of the LM2596 DC-DC step-down verter in low-power IoT applications Their research showed that the module efficientlyconverts voltage while maintaining stability under varying loads
con-• Chen et al (2021) highlighted the importance of heat dissipation in ensuringthe longevity of LM2596 converters, especially in environments with high ambienttemperatures
Research Gaps Identified
Despite significant advancements in IoT surveillance systems, several challenges remain:
1 Integration of Multiple Features:
• Few studies have combined real-time video streaming, motion detection, andremote control into a single, compact platform
2 Power Efficiency:
• Limited focus on optimizing power consumption for systems reliant on batteries
or solar power, which is critical for portable surveillance applications
3 Connectivity in Dynamic Environments:
• Existing studies primarily focus on static setups Mobile surveillance systemsoperating in varying network conditions remain underexplored
4 Scalability and Adaptability:
• Current solutions often lack flexibility to incorporate advanced features such asGPS-based tracking and AI-powered object detection
Relevance to This Study
This study aims to address these gaps by:
Trang 161 Integrating Core Functionalities:
• Combining video streaming using ESP32-CAM, motion detection via PIR sensors,and remote control through Telegram Bot in a single system
2 Improving Power Management:
• Utilizing LM2596 DC-DC converters for efficient power regulation and exploringtechniques to minimize energy waste
Trang 17Chapter 2 Analysis, Design, and System ment
The ESP32 CAM Car project involves a thorough analysis of both hardware and ware components to ensure seamless integration and efficient operation.[2] The systemcomprises two main aspects:
soft-1 Control Systems:
Planning and Integration: Designing a system to manage servo motors for tilt control and DC motors for movement required careful selection of componentsand precise calibration Each motor’s characteristics, including speed, torque, andresponsiveness, were analyzed to ensure smooth operation
pan-Motion Coordination: Synchronizing the pan-tilt mechanism with the car’smovement was critical to maintain stable video feeds during operation This requiredfine-tuning the control signals and implementing algorithms to prevent jerky motions.Control Algorithms: PID (Proportional-Integral-Derivative) control algorithmswere considered to enhance the precision and stability of servo motor movements Thisensures accurate targeting and consistent camera angles
2 Wireless Communication:
Real-Time Streaming: Utilizing WiFi for video streaming necessitated the plementation of efficient data compression and transmission protocols to reduce latencywithout compromising video quality The ESP32’s hardware-accelerated WiFi capa-bilities were fully leveraged
im-Remote Control: Establishing a reliable command-and-response system involveddesigning a robust communication protocol to handle simultaneous commands andreal-time video data
Telegram Integration: The Telegram Bot was integrated to provide a friendly interface for controlling the car remotely Features include:
user-• Real-time image capture commands
• Push notifications for status updates, such as Motion detection alerts
• Direct commands for PIR motion sensor, buzzer, and activating LEDs
Trang 18Environmental Considerations: Dynamic environments, such as those withmultiple WiFi networks or physical obstructions, were evaluated to optimize the sys-tem’s connectivity Techniques like signal strength monitoring and automatic recon-nection were incorporated.
3 System Adaptability:
Energy Efficiency: The system was designed to operate on limited power supplies,making efficient use of energy for both motors and the ESP32 module Techniques such
as dynamic power management and standby modes were explored
textbfCompactness and Modularity: Ensuring that the car’s components werelightweight and modular allowed for easy assembly, portability, and future upgrades.Versatility: The system was evaluated for multiple applications, including surveil-lance, remote monitoring, and educational robotics, making it adaptable to a range ofscenarios
Trang 191 Perception Layer
The Perception Layer serves as the system’s interface with the physical environment,gathering data and controlling actuators It comprises the following components:PIR Motion Sensor:
• Detects motion by sensing changes in infrared radiation
• Outputs a signal to the ESP32-CAM when motion is detected
• Critical for initiating alerts and ensuring system responsiveness in detecting curity events
se-ESP32-CAM Camera:
• Captures live video streams and images of the monitored environment
• Acts as the primary input device for visual data, providing real-time feedback tousers
DC Motors:
• Enable the movement of the car for dynamic surveillance
• Controlled via the L298N motor driver to perform forward, backward, left, andright movements
• Emits an audible alert when motion is detected
• Enhances situational awareness by providing immediate feedback during securityevents
• Hosted on the ESP32-CAM, it streams live video directly to the user’s device
• Ensures low latency (¡0.3 seconds) for real-time monitoring and control
Trang 203 Processing Layer
The Processing Layer is the ”brain” of the system, responsible for data processing,decision-making, and command execution:
ESP32-CAM:
• Central controller that:
- Processes inputs from the PIR sensor and commands from the Telegram bot
- Streams video to the web server
- Sends control signals to actuators like the servo motors and L298N motor driver.L298N Motor Driver:
• Converts the control signals from the ESP32-CAM into electrical signals for the
• Enables users to send commands and receive updates:
- Commands include car movement, camera adjustments, and toggling features(e.g., motion detection, LED flash)
- Notifications include motion detection alerts with attached images
• Provides a secure, intuitive, and widely accessible platform for interaction.User Device:
• The system is operated via:
- Telegram on a smartphone or PC for command input and alert reception
- A web browser for accessing the live video stream hosted by the ESP32-CAM’sweb server
• Ensures flexibility and ease of use, even for non-technical users
Integration Across IoT Layers
The seamless integration of these layers enables the system to function effectively:
1 Data Flow:
• Perception layer sensors and actuators generate data (e.g., motion signals, videostreams), which are processed by the processing layer
Trang 21• Processed data is transmitted via the network layer to the application layer foruser interaction.
• User commands from the application layer are relayed through the network andprocessing layers to control the perception layer components
Figure 2.2: System Design Diagram
1 Power Supply System
The power supply system is centered around a 2600 mAh, 12V lithium battery, whichpowers all the system components either directly or through a voltage regulator.1.1 Lithium Battery Characteristics
Energy Capacity:
The battery provides 2.6 Ah at 12V, corresponding to an energy capacity of:
Trang 22E = V × Icapacity = 12 V × 2.6 Ah = 31.2 W h (2.1)
• E: Energy capacity (Watt-hour)
• V: Voltage (12V)
• I: Battery capacity (2.6 Ah)
The system’s total current consumption is calculated as:
Itotal = IESP 32+ Iservo+ IP IR+ Ibuzzer+ Imotors (2.2)Example component currents:
• ESP32-CAM: 160mA,
• Servo motors: 500mA(peak for both),
• PIR motion sensor: 50mA,
• Buzzer: 40mA,
• DC motors (2 motors): 1000mA
Total current:
Itotal ≈ 1.75 A (2.3)Estimated operating time:
• High energy density: Lightweight and suitable for mobile systems
• Rechargeable: Long lifespan with minimal performance degradation
• Safety features: Equipped with protection circuits to prevent overcharge andovercurrent
(2.5)
Trang 23• Vin: Input voltage (12V).
• R1,R2 : Feedback resistors within the LM2596 circuit
1.4 Energy Consumption Calculation
The total power consumption of the system:
Ptotal= V × Itotal = 12V × 1.75A = 21W (2.6)With this consumption, the 2600 mAh lithium battery provides stable power for1.5 to 2 hours of operation under normal conditions
2 System Deployment: Web Server-Based Control
This section elaborates on the deployment of the IoT surveillance system, focusing onhow the ESP32-CAM, L298N motor driver, and peripheral components are integratedand controlled via a web server The design ensures seamless interaction between thehardware and the user
Figure 2.3: Motor and Servo System with ESP32-Cam
1 Core Functionalities
1 Real-Time Video Streaming:
• The ESP32-CAM acts as the central controller, streaming live video to a webinterface
• Users can access the video feed via any device (e.g., smartphone, tablet, or PC)connected to the same Wi-Fi network
2 DC Motor Control:
• The L298N motor driver is connected to two DC motors for mobility
• Commands sent via the web server are processed by the ESP32-CAM and lated into motor control signals through the L298N
trans-• Movement operations include:
- Forward, backward, left, and right turns
- Precise adjustments for navigation in various environments
Trang 243 Camera Orientation:
• Servo motors enable pan-tilt functionality for the ESP32-CAM camera
• Users can adjust the camera’s field of view remotely via the web interface fordynamic surveillance
2 Hardware Integration
1 ESP32-CAM:
Functionality:
• Acts as the central processing unit (CPU) of the system
• Hosts a web server for user interaction and video streaming
• Manages GPIO (General-Purpose Input/Output) pins to control peripheral vices
de-Operations:
• Connects to a Wi-Fi network to enable remote access
• Hosts a web interface for:
- Live video streaming
Bandwidth Calculation for Video Streaming:
Where:
B : Bandwidth required (bits/second)
R: Resolution of the video frame (e.g., 640x480 pixels)
F : Frame rate (frames per second, typically 30fps)
C : Color depth (e.g., 8 bits/pixel for grayscale, 24 bits/pixel for RGB)
- Receiving user commands for motor and camera movement
2 L298N Motor Driver:
Functionality:
o Controls the DC motors for forward, backward, left, and right movements
o Converts PWM signals from the ESP32-CAM into electrical outputs for motorcontrol
Trang 25D : Duty cycle.
Ton: Time the signal is HIGH
Ttotal : Total signal period
• Supports bi-directional movement by toggling the input pins:
- Example for forward movement:
- Input1 = HIGH, Input2 = LOW
• Outputs regulated voltage and current to the DC motors
3 DC Motors
Functionality:
• Provide mobility to the surveillance car
• Operate based on electrical signals from the L298N driver
Operations:
• Voltage is supplied by the L298N driver
• Rotational speed and direction are adjusted via PWM signals
3 Servo Motors:
Functionality:
• Enable pan-tilt functionality for the ESP32-CAM camera
• Adjust the horizontal and vertical angles of the camera for a dynamic field ofview
Operations:
• Controlled by PWM signals sent from the ESP32-CAM
Trang 26• The angle is determined by the width of the pulse in the PWM signal:
Where:
PW: Pulse width for servo motor (ms)
Angle: Desired servo angle (°)
Typical pulse widths:
Trang 27The ESP32-CAM powers on and initializes:
• The Wi-Fi connection
• Peripheral devices such as the PIR sensor, L298N motor driver, and servos.The system connects to the configured Wi-Fi network
• If the connection fails, it retries until successful
2 Web Server Setup
The ESP32-CAM hosts a local web server accessible via an IP address
The web server provides the following functionalities:
• Live video streaming: Streams video captured by the ESP32-CAM
• User commands: Allows users to send commands for mobility, pan-tilt ments, or sensor toggling
adjust-3 Command Execution
User commands sent through the web interface are processed by the ESP32-CAM.The ESP32-CAM executes the corresponding actions:
• Motor Movement:
- Forward/Backward: Activates both DC motors with identical PWM signals
- Left/Right Turn: Adjusts PWM signals to drive one motor faster or slower thanthe other
• The ESP32-CAM captures video frames and streams them via the web server
• Users access the video feed in real-time through a browser
Command Transmission:
• Users send commands (e.g., adjust servos, adjust camera) via the web interface
• Commands are transmitted over Wi-Fi to the ESP32-CAM for processing.Feedback:
• Alerts or updates (e.g., motion detection, camera status) are sent back to theuser through the interface
2 Timing and Latency
Trang 283 System Deployment: Telegram Bot-Based Control
This section explains the deployment of the system using Telegram bot-based control
It focuses on how the ESP32-CAM interacts with peripheral components, integrateshardware, and communicates with users in real time for efficient operation
Figure 2.6: ESP32-CAM WiFi and Telegram Integration
1 Core Functionalities
Real-Time Alerts
• The ESP32-CAM captures images when the PIR sensor detects motion
• Sends alerts and captured images via the Telegram bot to notify users instantly.Remote Command Execution
• Users can send commands via the Telegram bot, such as:
o ”Take Photo”
o ”Turn On/Off Alarm”
o ”Toggle Motion Detection”
• Commands are processed in real-time, and appropriate actions are executed.Motion Detection
• The PIR motion sensor monitors for changes in infrared radiation and triggers analert when motion is detected within its range of 3-7 m
Trang 29V =5V (supplied by the LM2596 regulator).
I =160mA (average operating current)
2 PIR Motion Sensor
The PIR (Passive Infrared) Motion Sensor is a critical component of the surveillancesystem, designed to detect motion by sensing changes in infrared radiation The sensorworks with Fresnel lenses to focus infrared signals and provide accurate detection Thediagram helps illustrate the operating principles and behavior of the PIR sensor.Operating Principle
Infrared Radiation and Detection
• The PIR sensor detects motion by measuring changes in infrared (IR) radiationlevels in its detection area
• Human bodies and other heat sources emit IR radiation, which is focused ontothe sensor’s detector through a Fresnel lens
• The sensor consists of two sensing elements:
o These elements compare IR levels between zones
o A difference in IR levels (caused by motion) generates an output signal
Dual Element Design
• The PIR sensor has two pyroelectric sensing elements placed side by side:
o When both elements sense the same IR level (no motion), the output signal iszero
o When a heat source (e.g., a person) moves across the sensor’s field, one elementdetects a change before the other, generating a positive or negative pulse as shown in
Trang 30the diagram.
Figure 2.7: How PIR Senor work
Output Signal
• The sensor produces a digital output (HIGH or LOW) based on detected motion:
o HIGH signal: Motion detected
o LOW signal: No motion detected
Detection Area and Sensitivity
• Operating voltage: 5V (supplied by LM2596)
Motion Detection Range Calculation:
The effective detection range can be calculated as:
Where:
d : Effective detection range
R=7 m: Maximum detection range
Trang 31theta=60 degree: Half of the PIR sensor’s field of view Example:
Sensitivity and Adjustments
• Most PIR sensors allow for sensitivity adjustments using a potentiometer:
o Increased sensitivity extends the range but may lead to false detections
o Lower sensitivity reduces false positives but limits the detection range
Signal Processing
Motion Detection
• The PIR sensor monitors changes in IR radiation:
o When a heat source moves into a new detection zone, it creates a differentialsignal
o This signal is amplified and processed by the onboard circuitry, producing a HIGHoutput
Output Timing
• The duration of the HIGH signal can be adjusted using the onboard timingpotentiometer:
o Typical output duration: 0.5-5 seconds
Heat Source Movement
• As shown in the diagram:
o Static heat sources: No output signal is generated since both sensing elementsreceive equal IR radiation
o Moving heat sources: Alternating signals (positive/negative pulses) are generated,resulting in a HIGH signal
Power consumption:
The PIR sensor operates at 5V, supplied by the LM2596 voltage regulator
Typical current consumption: 50mA
Trang 323 Step-by-Step Workflow
Figure 2.8: ESP32-CAM PIR Motion + Telegram Notifications Flowchart
1 System Initialization
• The ESP32-CAM initializes all connected components:
o PIR motion sensor
o Buzzer
• Connects to the Wi-Fi network to establish internet communication
• Initializes the Telegram bot API
2 Motion Detection
• The PIR motion sensor continuously monitors for motion
• When motion is detected:
o A HIGH signal is sent to the ESP32-CAM
o The ESP32-CAM captures an image and sends it to the user via Telegram
o The buzzer is activated for an audible alert
Trang 333 Remote Command Execution
• The user sends a command via the Telegram bot
• The ESP32-CAM receives the command and processes it:
o Take Photo: Captures an image and sends it via Telegram
o Activate Buzzer: Triggers the buzzer for a predefined duration
o Toggle PIR Sensor: Enables or disables motion detection
4 Feedback to the User
• After executing a command or detecting motion, the ESP32-CAM sends a firmation message or alert via Telegram
con-• The user receives real-time updates on system activity
4 Communication Workflow
1 Data Flow
• Alerts:
o The PIR sensor sends a HIGH signal to the ESP32-CAM upon detecting motion
o The ESP32-CAM captures an image and sends it to the Telegram bot
• Commands:
o Users send commands through Telegram to the ESP32-CAM
o The ESP32-CAM processes the commands and executes the required actions
2 Real-Time Interaction
• Motion alerts and command responses are delivered within seconds:
o Motion Detection to Alert: less than 2 s
o Command to Execution: less than 200 ms
3 Secure Communication
• Telegram Bot API ensures secure transmission of commands and data
• Alerts and images are sent only to the designated user account
4 Telegram Bot API Integration
Key Features
Trang 34condi-• /toggle pir: Enables or disables the motion detection sensor (PIR sensor).
• /alarm on: Activates an alarm mechanism, such as a buzzer, for security alerts
• /alarm off: Deactivates the alarm mechanism
exe-3 Image and Video Delivery
• The bot provides instant delivery of images captured by the ESP32-CAM module
• Future enhancements may include links to live video streams hosted by the ESP32module
Trang 35Implementation Steps
1 Creating the Telegram Bot
Figure 2.9: Create Telegram Bot
• Register a bot using the BotFather in the Telegram app and obtain the uniqueAPI token
• Configure the bot with commands and descriptions for user interaction
Trang 36• Use formatted text messages to provide feedback for other commands (e.g., ”PIRsensor is now enabled”).
5 Error Handling and Debugging
• Implement logging mechanisms to capture errors and unexpected behaviors
• Provide user-friendly error messages to ensure smooth interaction with the bot
• Use the Serial Monitor for debugging during development
Challenges and Solutions
1 Network Latency
• Challenge: Commands may experience delays under weak WiFi signals
• Solution: Optimize network settings and reduce data payload size for faster munication
com-2 Command Conflicts
• Challenge: Overlapping or repeated commands can cause inconsistent behavior
• Solution: Implement a queue system to process commands sequentially
3 Security
• Challenge: Protecting the bot and user data from unauthorized access
• Solution: Restrict access using chat IDs and secure the WiFi network with strongencryption
Benefits of Telegram Integration
1 Ease of Use: Telegram is a familiar platform with a straightforward interface,reducing the learning curve for users
2 Accessibility: As a cloud-based messaging service, Telegram enables globalaccess without additional infrastructure
3 Scalability: The system can handle multiple users and commands, making itsuitable for future expansions
control and monitoring, such as GPS tracking or environmental sensors
Trang 37By leveraging the Telegram Bot API, this project offers a powerful, user-friendlysolution for remotely controlling and monitoring the ESP32 CAM Car system, pavingthe way for innovative IoT applications.
Wiring Configuration
Figure 2.10: ESP32 CAM Car System Wiring Diagram
1 Battery to LM2596:
• The 12V lithium battery serves as the primary power source for the entire system
It connects to the input terminals of the LM2596 voltage regulator module
• The LM2596 reduces the 12V input to a stable 5V output, which is required topower various components including the ESP32-CAM modules, PIR motion sensor,servo motors, and the buzzer
• This voltage regulation ensures that the sensitive electronics operate safely andefficiently without risk of overvoltage damage
2 Battery to L298N:
• The 12V lithium battery is directly connected to the L298N motor driver module’spower input terminals
Trang 38• The L298N module uses the 12V input to drive the DC motors, which requirehigher voltage to operate effectively.
• Additionally, the L298N includes an onboard voltage regulator that provides astable 5V output to power connected components such as an ESP32-CAM module,ensuring seamless communication and operation
3 ESP32-CAM to servo motor:
• The ESP32-CAM module communicates with the servo motors through its GPIOpins, sending PWM (Pulse Width Modulation) signals to control their motion
• These servo motors are responsible for panning (horizontal movement) and tilting(vertical movement), allowing the ESP32-CAM to dynamically adjust its viewing angle
• This capability enhances the system’s ability to track motion or focus on specificareas for surveillance and monitoring tasks
4 ESP32-CAM to L298N motor driver:
• The ESP32-CAM[18] connects to the L298N motor driver via GPIO pins It sendscontrol signals to manage the operation of the DC motors
• By sending high and low signals to the motor driver’s input pins, the ESP32-CAMcan command the robot to move forward, backward, or turn left or right
• This integration ensures precise navigation and control of the robotic car
move-6 ESP32-CAM to PIR Motion Sensor and Buzzer (Integrated TelegramControl):
• PIR Motion Sensor:
o The PIR motion sensor is connected to a GPIO pin of the ESP32-CAM to sendsignals when motion is detected
o Upon detecting motion, the ESP32-CAM performs the following actions:
1 Capture Image: Takes a photo using the integrated camera module