Human Fall Detection System using RDK X5 D-Robotics
Last Updated on September 11, 2026 by Engr. Shahzada Fahad
Description:
Human Fall Detection System using RDK X5 D-Robotics – What if your system could and react in real time?

Today, I am building a Fall Detection System using AI on the powerful RDK X5,

Combined with a MIPI camera for real-time vision.

And when a fall happens… this system can trigger anything;
A buzzer, LED, email alert, or even a complete emergency response system.
So in this project, we are using AI body tracking with keypoints to detect when a person falls or lies down.

For demonstration, I will turn ON an LED when a fall is detected.
But you can easily upgrade this into a smart healthcare system or home safety system.

Now let’s build it step by step.
Table of Contents
Amazon Links:
*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!
For this project, I am using an LED; but you can connect anything you want.
For example:
A buzzer
A relay module
Or even trigger another circuit
So whenever a fall is detected…
The GPIO 37 pin will go HIGH and activate your device.
Simple… but very powerful
STEP 1 – CREATE PROJECT FOLDER
First, open the terminal and create a project folder:

mkdir -p ~/Desktop/fall_project
STEP 2 – NUCLEAR FIX (VERY IMPORTANT)
Now before anything… we need to apply something called the Nuclear Fix.
Why this is needed?
By default, the AI system sometimes does NOT give body keypoints like shoulders and hips.
And without these… fall detection is impossible.
So this fix forces the system to:
Always enable keypoints detection
Think of it like this:
Without fix → system is blind ❌
With fix → full body tracking ✅
That’s why I call it Nuclear Fix; it overrides everything.

Now copy and paste the command I provided.
Nuclear fix:
# 1. Define the Keypoint Configuration (The new settings)
JSON_CONTENT='{
“model_file_path”: “multitask_body_head_face_hand_kps_960x544.hbm”,
“dnn_Parser”: {
“pixel_prob_threshold”: 0.5,
“kps_pos_distance”: 5.0,
“kps_neg_distance”: 5.0,
“enable_kps”: 1
}
}’
# 2. Back up the original file (Just in case)
sudo cp /opt/tros/humble/lib/mono2d_body_detection/config/iou2_method_param.json /opt/tros/humble/lib/mono2d_body_detection/config/iou2_method_param.json.bak
# 3. Overwrite the Standard Detection Config
# This uses ‘sudo bash -c’ to write directly into the protected system folder
sudo bash -c “echo ‘$JSON_CONTENT’ > /opt/tros/humble/lib/mono2d_body_detection/config/iou2_method_param.json”
# 4. Overwrite the “Euclid/Tracking” Config (Double Tap)
# This ensures that even if the robot switches modes, it still uses our settings
sudo bash -c “echo ‘$JSON_CONTENT’ > /opt/tros/humble/lib/mono2d_body_detection/config/iou2_euclid_method_param.json”
echo “✅ NUCLEAR FIX APPLIED: System defaults now force Keypoints ON.”
After this step, your AI is ready for fall detection.
STEP 3 – CREATE FALL DETECTION CODE
Now create the main file:

nano ~/Desktop/fall_project/fall_node.py
Copy and paste this code:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
#!/usr/bin/env python3 import rclpy from rclpy.node import Node from rclpy.qos import QoSProfile, ReliabilityPolicy, HistoryPolicy, DurabilityPolicy from ai_msgs.msg import PerceptionTargets import Hobot.GPIO as GPIO import os import time # --- CONFIGURATION --- ALARM_PIN = 37 # Same pin as before (Connect LED or Buzzer here) # Keypoint IDs (COCO Format) L_SHOULDER, R_SHOULDER = 5, 6 L_HIP, R_HIP = 11, 12 class FallDetector(Node): def __init__(self): super().__init__('fall_node') qos = QoSProfile(reliability=ReliabilityPolicy.BEST_EFFORT, durability=DurabilityPolicy.VOLATILE, history=HistoryPolicy.KEEP_LAST, depth=10) self.create_subscription(PerceptionTargets, '/hobot_mono2d_body_detection', self.callback, qos) self.state = "STANDING" # Setup GPIO GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) GPIO.setup(ALARM_PIN, GPIO.OUT) GPIO.output(ALARM_PIN, GPIO.LOW) self.get_logger().info("FALL DETECTION STARTED.") def callback(self, msg): os.system('clear') print("="*40 + f"\n ?? FALL DETECTOR SYSTEM ??\n" + "="*40) if not msg.targets: print("\nStatus: Scanning area...") return skeleton = None for t in msg.targets: for point_group in t.points: if point_group.type == "body_kps": skeleton = point_group.point break if skeleton: break if skeleton is None: print("\nStatus: Person detected, looking for skeleton...") return try: # 1. Calculate Spine Vector # Mid-point between shoulders shoulder_x = (skeleton[L_SHOULDER].x + skeleton[R_SHOULDER].x) / 2.0 shoulder_y = (skeleton[L_SHOULDER].y + skeleton[R_SHOULDER].y) / 2.0 # Mid-point between hips hip_x = (skeleton[L_HIP].x + skeleton[R_HIP].x) / 2.0 hip_y = (skeleton[L_HIP].y + skeleton[R_HIP].y) / 2.0 # 2. Compare Dimensions # Vertical Distance (Height of torso) vertical_len = abs(shoulder_y - hip_y) # Horizontal Distance (Width of torso lean) horizontal_len = abs(shoulder_x - hip_x) # 3. Logic: # If the body covers more X distance than Y distance, it is Horizontal (Lying Down) if horizontal_len > vertical_len: self.state = "FALL DETECTED!" # Turn LED ON GPIO.output(ALARM_PIN, GPIO.HIGH) print(f"\n ?? STATUS: {self.state}") print(f" (Please help!)") else: self.state = "OK (Standing)" # Turn LED OFF GPIO.output(ALARM_PIN, GPIO.LOW) print(f"\n ? STATUS: {self.state}") # Debug Info print(f"\n Torso Vertical: {int(vertical_len)} px") print(f" Torso Horizontal: {int(horizontal_len)} px") except Exception as e: print(f"Math Error: {e}") def destroy_node(self): GPIO.output(ALARM_PIN, GPIO.LOW) GPIO.cleanup() super().destroy_node() def main(): rclpy.init() try: rclpy.spin(FallDetector()) except KeyboardInterrupt: pass finally: GPIO.cleanup() rclpy.shutdown() if __name__ == '__main__': main() |
Let me quickly tell you; what this code is doing
It reads body keypoints
Finds:
Shoulders midpoint
Hips midpoint
Then it compares:
Body height (vertical)
Body width (horizontal)
Main logic:
If body is vertical → standing
If body becomes horizontal → fall detected
This line is the brain of the system:
if horizontal_len > vertical_len:
Means the person has fallen or is lying down
And this turns ON the LED:
GPIO.output(ALARM_PIN, GPIO.HIGH)
STEP 4 – CREATE START SCRIPT
Now let’s create another file:

command:
nano ~/Desktop/fall_project/start_clean_fall.py
Copy and paste this code:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
#!/usr/bin/env python3 import subprocess import time import os import signal import sys def main(): home = os.path.expanduser("~") logic_script = os.path.join(home, "Desktop/fall_project/fall_node.py") print("========================================") print(" ?? STARTING FALL DETECTION ") print("========================================") os.system("pkill -f mono2d_body_detection") os.system("pkill -f body_tracking") print("[1/2] Launching AI (Hidden)...") # Using body_tracking to guarantee web visuals ai_cmd = "export CAM_TYPE=mipi; source /opt/tros/humble/setup.bash; ros2 launch body_tracking body_tracking_without_gesture.launch.py" ai_process = subprocess.Popen( ai_cmd, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, executable='/bin/bash' ) try: for i in range(5, 0, -1): print(f" Ready in {i}...") time.sleep(1) print("[2/2] Starting Dashboard...") time.sleep(1) if os.path.exists(logic_script): os.system(f"python3 {logic_script}") else: print(f"Error: Could not find {logic_script}") except KeyboardInterrupt: pass finally: print("\nStopping AI...") try: os.killpg(os.getpgid(ai_process.pid), signal.SIGTERM) except: pass print("Done.") if __name__ == "__main__": main() |
This script
Starts the AI detection system
Cleans previous processes
Runs your fall detection code smoothly
So you don’t have to run multiple commands manually.
Alright… now everything is set.
Let’s go ahead and close this file and any other open windows, because our project is now fully ready.
STEP 5 – RUN THE PROJECT
To run this project, first make sure you are on the Desktop…

Then open the terminal…

And now we are going to start the entire system
Command:
source /opt/tros/humble/setup.bash
This command Loads all ROS2 and AI environment settings

Command:
python3 ~/Desktop/fall_project/start_clean_fall.py
This second command:

Starts the whole system:
- AI detection
- Body tracking
- Your fall detection logic
STEP 6 – OPEN DASHBOARD
Now open this in your browser:

What this does:
Shows live camera feed

Displays AI body detection

You can visually see:
Person detection
Body movement

This is very useful to:
Debug the system
See how AI is tracking your body
FULL DEMO (REAL-TIME TEST)
Alright… now comes the most exciting part; let’s actually test this system in real time.
So right now; I am just standing normally in front of the camera.

Nothing special.
And if you look at the system; it clearly understands that I am standing.
Why?

Because my body is vertical, my shoulders are above my hips, and the height of my body is greater than its width.
So the system says: “OK – Standing”
And you can see… the LED is OFF. Perfect.

Now let’s take it to the next level; I am going to simulate a fall.
Watch carefully…
As I fall… and lie down on the floor…

Now my body position completely changes.
Instead of being vertical; my body becomes horizontal.
Now the width of my body is greater than its height.
And boom

Instantly the system reacts:
Fall detected
LED turns ON
No delay… no confusion…just real-time fall detection.
So this is how you can build a real-time AI fall detection system.
You can extend this project by:
Sending alerts
Triggering alarms
Connecting to IoT or cloud
And if you want the full project…
You can download the complete source code, all resources, and a detailed step-by-step document from my Patreon.
I have explained each and every command, so you can easily build this project without any confusion.
Go check it out… and start building
So, that’s all for now.
Support me on Patreon:
If you enjoy my work and find these projects helpful, please consider supporting me on Patreon. With just $1, you can get access to all project source codes, schematics, and extra resources that I share with my supporters. Your support helps me continue creating new electronics tutorials, experiments, and open projects for the community. Thank you so much for being part of this journey and for supporting my work!
Watch Video Tutorial:
Discover more from Electronic Clinic
Subscribe to get the latest posts sent to your email.



