Tech Gyan Set
Published © MIT

IoT-Based Real-Time Fall Detection & Emergency Alert System

An IoT-based system that detects elderly falls in real time and instantly sends emergency alerts for faster response. πŸš‘πŸ“‘

BeginnerFull instructions provided8 hours52
IoT-Based Real-Time Fall Detection & Emergency Alert System

Things used in this project

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

πŸš‘ IoT-Based Real-Time Fall Detection & Emergency Alert System βœ… Complete ESP32 Code (Numbered)

C/C++
// 1️⃣ Required Libraries
1  #include <Wire.h>                 
2  #include <MPU6050.h>              

// Use: I2C communication aur accelerometer control ke liye.
// 2️⃣ Create MPU Object
3  MPU6050 mpu;

// Use: MPU6050 sensor ka object initialize karta hai.
// 3️⃣ Pin Definitions
4  #define BUZZER 4
5  #define CANCEL_BUTTON 5

// Use: Buzzer aur cancel button ke GPIO define karta hai.
// 4️⃣ GSM Serial Setup
6  HardwareSerial gsmSerial(2);

// Use: GSM module communication ke liye Serial2 use karta hai.
// 5️⃣ Fall Detection Thresholds
7  float fallThreshold = 2.5;     
8  bool fallDetected = false;

// Use: Sudden impact detect karne ke liye threshold define karta hai.
// 6️⃣ Setup Function
9  void setup() {

10   Serial.begin(115200);
11   Wire.begin();
12   mpu.initialize();

13   pinMode(BUZZER, OUTPUT);
14   pinMode(CANCEL_BUTTON, INPUT_PULLUP);

15   gsmSerial.begin(9600, SERIAL_8N1, 16, 17);

16   Serial.println("System Ready");
17 }

// Use: Sensor, GSM aur hardware initialize karta hai.
// 7️⃣ Send SMS Function
18 void sendSMS() {
19   gsmSerial.println("AT");
20   delay(1000);
21   gsmSerial.println("AT+CMGF=1");
22   delay(1000);
23   gsmSerial.println("AT+CMGS=\"+91XXXXXXXXXX\"");
24   delay(1000);
25   gsmSerial.print("Emergency! Fall detected.");
26   delay(100);
27   gsmSerial.write(26);
28   delay(3000);
29 }

// Use: Emergency contact ko SMS bhejne ke liye AT command use karta hai.
// 8️⃣ Main Loop
30 void loop() {

31   int16_t ax, ay, az;
32   mpu.getAcceleration(&ax, &ay, &az);

πŸ”Ή Use: Accelerometer data read karta hai.

33   float accelX = ax / 16384.0;
34   float accelY = ay / 16384.0;
35   float accelZ = az / 16384.0;

πŸ”Ή Use: Raw data ko g-force me convert karta hai.

36   float totalAccel = sqrt(accelX * accelX + accelY * accelY + accelZ * accelZ);

πŸ”Ή Use: Total acceleration magnitude calculate karta hai.

37   if(totalAccel > fallThreshold) {
38     fallDetected = true;
39   }

πŸ”Ή Use: Sudden impact threshold cross hone par fall detect karta hai.

40   if(fallDetected) {

41     digitalWrite(BUZZER, HIGH);
42     Serial.println("Fall Detected!");

πŸ”Ή Use: Fall hone par buzzer ON karta hai.

43     delay(10000);

πŸ”Ή Use: 10 second cancel window deta hai.

44     if(digitalRead(CANCEL_BUTTON) == HIGH) {
45       sendSMS();
46     }

πŸ”Ή Use: Agar cancel button press nahi hua to SMS bhejta hai.

47     digitalWrite(BUZZER, LOW);
48     fallDetected = false;
49   }

50   delay(500);
51 }

πŸ”Ή Use: Alert reset karta hai aur system continue karta hai.

Credits

Tech Gyan Set
20 projects β€’ 6 followers
Thanks to Tech Gyan Set .

Comments