Fall detection using radar sensor ld2410b

Hi, I have a project about fall detection in hospital toilets using esp32, radar sensors, motion sensors and LDR sensors. for now, my coding doesn't seem to give the correct reading but I don't know if the code I made is correct or not. can anyone help to make sure my code is correct? My project is done by placing the system on the ceiling and radiating on a closed area of ​​1.7m x 1.2m x 1.4m

#include <SPI.h>
#include <LoRa.h>
#include <ld2410.h>

#define BAND 915E6
#define NSS_PIN 15    // Chip Select Pin
#define RST_PIN 4     // Reset Pin
#define DI0_PIN 34    // Interrupt Pin for DIO0

#define MONITOR_SERIAL Serial
#define RADAR_SERIAL Serial1
#define RADAR_RX_PIN 16
#define RADAR_TX_PIN 17

ld2410 radar;
uint32_t lastReading = 0;
uint32_t lastAlertTime = 0; // Timer for 10-second alerts
float currentDistance = 0.0;

// LED pins
const int greenLEDPin = 12; // Green LED for motion detection
const int yellowLEDPin = 14; // Yellow LED for LoRa transmission
const int redLEDPin = 13;    // Red LED for fall/emergency

// Constants for fall detection
const float fallDistanceThreshold = 0.8; // Distance in meters indicating a fall
const unsigned long fallAlertCooldown = 5000; // 5 seconds cooldown for fall alerts
const unsigned long alertInterval = 10000;    // 10 seconds alert interval
unsigned long lastFallAlertTime = 0;

void setup() {
    Serial.begin(9600);
    pinMode(greenLEDPin, OUTPUT);
    pinMode(yellowLEDPin, OUTPUT);
    pinMode(redLEDPin, OUTPUT);

    delay(100);

    // Initialize LoRa
    SPI.begin();
    LoRa.setPins(NSS_PIN, RST_PIN, DI0_PIN);

    if (!LoRa.begin(BAND)) {
        Serial.println("LoRa initialization failed. Check your connections.");
    } else {
        Serial.println("LoRa transmitter initialized.");
    }

    // Initialize Radar
    MONITOR_SERIAL.begin(115200);
    RADAR_SERIAL.begin(256000, SERIAL_8N1, RADAR_RX_PIN, RADAR_TX_PIN);
    if (radar.begin(RADAR_SERIAL)) {
        MONITOR_SERIAL.println(F("Radar Initialized"));
    } else {
        sendMessage("B1 : Faulty");
    }
}

void loop() {
    radar.read();

    // Ensure the radar is connected and we read at intervals
    if (radar.isConnected() && millis() - lastReading > 500) {
        lastReading = millis();
        String alertMessage;

        if (radar.presenceDetected()) {
            digitalWrite(greenLEDPin, HIGH); // Indicate presence with green LED

            if (radar.movingTargetDetected()) {
                currentDistance = radar.movingTargetDistance() / 100.0; // Convert to meters
                Serial.print("Target moving. Distance: ");
                Serial.print(currentDistance);
                Serial.println(" m");
                alertMessage = "B1 : Target moving";
            } else {
                currentDistance = radar.stationaryTargetDistance() / 100.0; // Convert to meters
                Serial.print("Target detected. Stationary. Distance: ");
                Serial.print(currentDistance);
                Serial.println(" m");
                alertMessage = "B1 : Target stationary";
            }

            // Check for fall detection
            if (currentDistance > fallDistanceThreshold && millis() - lastFallAlertTime > fallAlertCooldown) {
                Serial.println("Fall detected!");
                alertMessage = "B1 : Fall detected! Emergency!";
                digitalWrite(redLEDPin, HIGH); // Indicate fall with red LED
                delay(500);
                digitalWrite(redLEDPin, LOW);
                lastFallAlertTime = millis(); // Update fall alert cooldown
            }
        } else {
            // No target detected
            digitalWrite(greenLEDPin, LOW); // Turn off green LED
            Serial.println("No target detected.");
            alertMessage = "B1 : Vacant";
        }

        // Send alert every 10 seconds
        if (millis() - lastAlertTime > alertInterval) {
            sendMessage(alertMessage);
            lastAlertTime = millis(); // Update last alert time
        }
    }

    delay(1000); // Main loop delay
}

void sendMessage(String message) {
    Serial.println("Sending LoRa message: " + message);
    digitalWrite(yellowLEDPin, HIGH); // Turn on yellow LED for transmission

    if (LoRa.beginPacket()) {
        LoRa.print(message);
        if (LoRa.endPacket()) {
            Serial.println("LoRa packet sent successfully.");
        } else {
            Serial.println("LoRa packet sending failed!");
        }
    } else {
        Serial.println("Failed to start LoRa packet!");
    }

    delay(500); // Delay for yellow LED visibility
    digitalWrite(yellowLEDPin, LOW); // Turn off yellow LED after transmission
}

Doesn't seem to.... Can You make sure You know what's wrong? How will helpers know?

Without the hardware it's very difficult, and time consuming. Helpers are volountares and are not eager to take on that work.

1 Like

So which device are you testing and why do you think the results are wrong?

i think it's wrong because when i fall, the radar sensor not give output 'target fall' . i already try to make it less sensitivity but still cannot detect fall when target fall.

Oh, im sorry for the misunderstanding. It's wrong because when I fall, the radar sensor does not give the output 'target fall'. I already try to make it less sensitive but still cannot detect a fall when the target falls.

Perhaps sensitivity is NOT the problem!

const float fallDistanceThreshold = 0.8; // Distance in meters indicating a fall

That device only has a recolution of 0.75 meters. So it's unlikely you will detect a fall with a 0.8m threshold. The difference is only 50mm

What do any of these have to do with only falling, and not just moving (walking, wheelchair, sitting and standing, in particular)?

Use an accelerometer to sense sudden stops (large acceleration over a short span of time).
https://docs.arduino.cc/built-in-examples/sensors/ADXL3xx/

Do you need HardwareSerial.h to instantiate Serial1?

Most modern 3D accelerometers have a jolt and/or free fall detection interrupt built in.

Example

1 Like

The OP seems to be developing a passive sensing system, but also seems to want an immediate solution from the forum.

When I was first allowed to use a toilet after a hospital visit, the intern's duty was to hold my hand as I dropped the kids off at the poool.
image

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.