Designing a Wi-Fi CCTV Camera Using ESP32-CAM with PIR Motion Detection and Firebase Integration

The ESP32-CAM module enables compact and cost-effective smart surveillance systems by combining Wi-Fi connectivity and camera streaming in a single microcontroller board. In this project, a Wi-Fi CCTV camera was developed with motion detection, Firebase cloud integration, Android monitoring, and SD card recording capability.
This system was designed not only for local monitoring, but also for cloud synchronization and remote configuration.
Hardware Architecture

The core of the system is the AI Thinker ESP32-CAM board configured via Arduino IDE.
The hardware components include:
- ESP32-CAM
- PIR motion sensor
- Buzzer alarm
- Push button (Setup/Reset)
- 5V regulated adaptor
- SD card storage
The wiring architecture is illustrated in the wiring diagram, showing:
- PIR output connected to ESP32-CAM GPIO
- Buzzer driven through transistor stage
- External buttons for programming and setup
- 5VDC regulated supply

Board component placement is detailed in the board layout section, clearly identifying PIR, buzzer, supply adaptor input, and button.
Motion Detection and Alarm Logic
The PIR sensor continuously monitors environmental movement. When motion is detected:
- ESP32-CAM sets motion flag.
- Buzzer alarm activates.
- Motion status is written to Firebase.
- Android app displays detection notification.
- Optional SD card recording is triggered.
The Android application interface shows:
- Motion Detection toggle
- Buzzer enable/disable
- SD recording control
- Video streaming window
To prevent repeated triggers, the system requires manual reset after detection.
Firebase Realtime Database Integration
Cloud integration is implemented through Firebase Realtime Database setup.
The process includes:
- Creating Firebase project
- Enabling Realtime Database
- Configuring database rules (read/write true)
- Importing JSON structure
- Retrieving Firebase host and database secret
These credentials are configured inside the ESP32 firmware and Android application.
The system updates:
- Motion status
- Device state
- Alarm flags
This enables real-time cloud synchronization.
Android Application (Kodular)
The Android application is developed using Kodular.
Configuration steps include:
- Importing .aia project
- Setting Firebase URL and secret
- Building APK file

The app provides:
- Live video streaming
- Motion detection control
- Alarm control
- SD card recording activation
- Device setup interface
Offline and Setup Mode
If Wi-Fi is unavailable for 30 seconds, the device enters offline mode.
In offline mode:
- Local streaming remains active
- SD recording continues
- Cloud synchronization pauses
The setup procedure includes boot-time button press to enter configuration mode, allowing users to configure Wi-Fi SSID, password, and Firebase credentials.
Enclosure and Deployment

The panel box installation shows:
- Front PIR window
- Camera lens opening
- SD card access
- External reset button
- 5V adaptor input
This transforms the system from a development prototype into a deployable surveillance unit.
Engineering Considerations
Key design considerations:
- Separate motion detection logic from streaming loop
- Use transistor driver for buzzer stability
- Avoid excessive Firebase writes
- Implement auto-reconnect Wi-Fi logic
- Maintain SD recording independent of cloud status
This architecture ensures reliable operation in both local and connected environments.
Conclusion
The Wi-Fi CCTV Camera using ESP32-CAM demonstrates a practical IoT-based surveillance solution integrating motion detection, cloud database synchronization, Android monitoring, and SD card recording.
By combining embedded firmware, cloud backend, and mobile interface, this project provides a scalable and cost-effective smart security platform suitable for home and small industrial applications.
#IoTProject#
#ESP32CAM#
#WiFiCCTV#
#FirebaseRealtimeDatabase#
#PIRSensor#
#EmbeddedSystem#
#AndroidMonitoring#
#Kodular#
#SmartSecurity#
#MotionDetection#
Sign In Or Register Comment after
No comments yet. Be the first to comment!