Elderly Fall Detection with ESP32 and Accelerometer
A wearable fall detection system can automatically recognize sudden movements or impacts and send an alert to caregivers in real-time.
In this project, we use an ESP32 microcontroller and an accelerometer sensor to detect falls and transmit alerts over Wi-Fi or GSM.
Key Features
- Fall detection using an accelerometer (sudden acceleration change).
- Real-time alert notifications (via Wi-Fi or SMS).
- Low-power wearable design for continuous monitoring.
- Optional SOS button for manual emergency alerts.
- Cloud or mobile app integration for caregiver monitoring.
Components Required
- ESP32 development board
- Accelerometer module (e.g., MPU6050, ADXL345, or MPU9250)
- Push button (for SOS manual alert)
- Buzzer or vibration motor (local alert)
- Li-Po battery with charging circuit
- Wi-Fi (built-in ESP32) or GSM module for communication
System Overview
- The accelerometer continuously monitors acceleration in X, Y, and Z axes.
- A sudden change in acceleration (beyond a threshold) is classified as a fall event.
- The ESP32 triggers an alert sequence, which may include:
- Sending an alert to a mobile app or cloud server.
- Notifying caregivers via SMS, email, or push notification.
- Activating a local buzzer/vibration motor.
- Caregivers can respond immediately to assist the elderly individual.
Example Code (ESP32 + MPU6050 + Wi-Fi HTTP Alert)
c
#include <Wire.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include "MPU6050.h"
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
const char* serverUrl = "http://your-server.com/api/fall-alert";
MPU6050 mpu;
float ax, ay, az;
const float fallThreshold = 2.5; // g-force threshold for fall detection
unsigned long lastCheck = 0;
void setup() {
Serial.begin(115200);
Wire.begin();
// Initialize MPU6050
mpu.initialize();
if (!mpu.testConnection()) {
Serial.println("MPU6050 connection failed");
while (1);
}
// Connect Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nWi-Fi connected");
}
void loop() {
mpu.getAcceleration(&ax, &ay, &az);
// Convert raw values to g-force
float gX = ax / 16384.0;
float gY = ay / 16384.0;
float gZ = az / 16384.0;
float magnitude = sqrt(gX * gX + gY * gY + gZ * gZ);
if (millis() - lastCheck > 1000) {
lastCheck = millis();
Serial.print("Accel Magnitude: ");
Serial.println(magnitude);
}
// Check for fall (sudden impact)
if (magnitude > fallThreshold) {
Serial.println("Fall Detected!");
sendFallAlert(gX, gY, gZ);
delay(5000); // avoid duplicate alerts
}
}
void sendFallAlert(float gx, float gy, float gz) {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin(serverUrl);
http.addHeader("Content-Type", "application/json");
String jsonData = "{\"event\":\"fall_detected\",\"gx\":" + String(gx, 2) +
",\"gy\":" + String(gy, 2) + ",\"gz\":" + String(gz, 2) + "}";
int httpResponseCode = http.POST(jsonData);
if (httpResponseCode > 0) {
Serial.println("Alert sent successfully");
} else {
Serial.println("Error sending alert");
}
http.end();
}
}