A comprehensive IoT solution for real-time fall detection, monitoring, and alerting using ESP8266 microcontrollers with IMU sensors, Flask API backend, MongoDB Atlas database, and a Streamlit dashboard interface.
This system is designed to detect falls among elderly or at-risk individuals using wearable devices. Upon detecting a fall, the system immediately sends alerts to registered caretakers via SMS and records the incident for future reference. Caretakers can monitor multiple users through a web-based dashboard.
-
Hardware
- ESP8266 microcontroller
- MPU6050/MPU9250 IMU sensor (accelerometer and gyroscope)
- Battery power supply
-
Backend
- Flask API for data ingestion and alert processing
- MongoDB Atlas for cloud database storage
- SMS service integration
-
Frontend
- Streamlit dashboard for caretakers
- User management interface
- Incident visualization and history
- Real-time fall detection using algorithms
- Instant SMS alerts to caretakers when falls are detected
- User management to monitor multiple individuals
- Historical data analysis of movements and incidents
- Secure cloud storage of all detection data
- Responsive web dashboard for desktop and mobile access
- Python 3.8+
- Arduino IDE
- MongoDB Atlas account
- SMS service API keys (Twilio recommended)
- Internet connection for IoT devices
-
ESP8266 & IMU Configuration
1. Connect the MPU6050/MPU9250 to the ESP8266: - VCC to 3.3V - GND to GND - SCL to D1 - SDA to D2 2. Flash the ESP8266 with the provided firmware 3. Configure WiFi credentials in the code -
Power Supply
- Connect a 3.7V LiPo battery
- Ensure proper charging circuit implementation
-
Flask API
# Clone the repository git clone https://github.com/CodeWithAlvin/fallDetection cd fall-detection-system/backend # Create and activate virtual environment python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate # Install dependencies pip install -r requirements.txt # Configure environment variables cp .env.example .env # Edit .env with your MongoDB and SMS service credentials # Run the Flask API python app.py
-
MongoDB Atlas Configuration
- Create a cluster in MongoDB Atlas
- Create a database named
fall_detection - Create collections:
users,patients,fallDetection - Configure network access for your API server
-
SMS Service Setup
- Register for a Twilio account (or alternative SMS service)
- Obtain API credentials
- Add these credentials to your
.envfile
- Streamlit Dashboard
cd fallDetection/streamlit # Install dependencies pip install -r requirements.txt # Run the Streamlit app streamlit run app.py
- Power on the ESP8266 device
- The device will connect to WiFi and register with the backend
- Log in to the Streamlit dashboard
- Go to "Devices" and assign the new device to a user
- Navigate to "Users" section in the dashboard
- Add new users with their details:
- Name
- Age
- Contact information
- Emergency contacts (for SMS alerts)
- Assign devices to users
-
The dashboard will display:
- Real-time status of all users
- Recent alerts with severity levels
- Fall history with timestamps and locations
- Device battery status
-
SMS alerts will be automatically sent to registered caretakers when:
- A fall is detected
- Device battery is critically low
- Device goes offline unexpectedly
The ESP8266 firmware includes:
- WiFi connection management
- IMU sensor data processing
- Fall detection algorithms
- HTTP communication with Flask API
- Power management routines
-
Home Screen
- Overview of all users
- Active alerts
- System health status
-
User Management
- Add/Edit/Remove users
- Assign devices to users
- Manage emergency contacts
-
Alert History
- Timeline of detected falls
- Filtering by user, date, and severity
- Export functionality for medical records
-
Analytics
- Trends in user activity
- Fall frequency analysis
- Device performance metrics
-
Device Not Connecting
- Check WiFi signal strength
- Verify credentials in the firmware
- Ensure backend API is running
-
False Alerts
- Adjust sensitivity settings in the device configuration
- Update firmware to latest version
- Ensure device is worn correctly
-
Missing SMS Alerts
- Verify SMS service credits and account status
- Check phone numbers are in correct format (include country code)
- Review API logs for error messages
Contributions to the project are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.