Example Code for Arduino-Fall-Information
This article offers a step-by-step guide to setting up fall detection using Arduino, the C1001 Millimeter Wave Sensor, and ESP32-S3-DevKitC-1. It covers necessary hardware and software, wiring diagrams, and sample code for configuring sensors, highlighting key parameters like fall sensitivity and sensor installation height.
Hardware Preparation
- C1001 Millimeter Wave Human Detection Sensor
- ESP32-S3-DevKitC-1 Development Board, or other ESP32-based development boards.
Software Preparation
- Arduino IDE, Click to download Arduino IDE
- DFRobot_HumanDetection library, Click to download DFRobot_HumanDetection library
- How to install library files, Click the link
Wiring Diagram
| Millimeter Wave | ESP32-S3 |
|---|---|
| VIN | 5V |
| GND | GND |
| RX | IO5 |
| TX | IO4 |
Other Preparation Work
There are no special installation requirements for human presence detection, both top and side installations are possible. For fall detection, the sensor should be installed directly above the test area, with the front of the sensor facing down. As shown below.
Sample Code
/**!
* @file basics.ino
* @brief This is the fall detection usage routine of the C1001 mmWave Human Detection Sensor.
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @license The MIT License (MIT)
* @author [tangjie]([email protected])
* @version V1.0
* @date 2024-06-03
* @url https://github.com/DFRobot/DFRobot_HumanDetection
*/
#include "DFRobot_HumanDetection.h"
DFRobot_HumanDetection hu(&Serial1);
void setup() {
Serial.begin(115200);
Serial1.begin(115200, SERIAL_8N1, 4, 5);
Serial.println("Start initialization");
while (hu.begin() != 0) {
Serial.println("init error!!!");
delay(1000);
}
Serial.println("Initialization successful");
Serial.println("Start switching work mode");
while (hu.configWorkMode(hu.eFallingMode) != 0) {
Serial.println("error!!!");
delay(1000);
}
Serial.println("Work mode switch successful");
hu.configLEDLight(hu.eFALLLed, 1); // Set HP LED switch, it will not light up even if the sensor detects a person present when set to 0.
hu.configLEDLight(hu.eHPLed, 1); // Set FALL LED switch, it will not light up even if the sensor detects a person falling when set to 0.
hu.dmInstallHeight(270); // Set installation height, it needs to be set according to the actual height of the surface from the sensor, unit: CM.
hu.dmFallTime(5); // Set fall time, the sensor needs to delay the current set time after detecting a person falling before outputting the detected fall, this can avoid false triggering, unit: seconds.
hu.dmUnmannedTime(1); // Set unattended time, when a person leaves the sensor detection range, the sensor delays a period of time before outputting a no person status, unit: seconds.
hu.dmFallConfig(hu.eResidenceTime, 200); // Set dwell time, when a person remains still within the sensor detection range for more than the set time, the sensor outputs a stationary dwell status. Unit: seconds.
hu.dmFallConfig(hu.eFallSensitivityC, 3); // Set fall sensitivity, range 0~3, the larger the value, the more sensitive.
hu.sensorRet(); // Module reset, must perform sensorRet after setting data, otherwise the sensor may not be usable.
Serial.print("Current work mode:");
switch (hu.getWorkMode()) {
case 1:
Serial.println("Fall detection mode");
break;
case 2:
Serial.println("Sleep detection mode");
break;
default:
Serial.println("Read error");
}
Serial.print("HP LED status:");
switch (hu.getLEDLightState(hu.eHPLed)) {
case 0:
Serial.println("Off");
break;
case 1:
Serial.println("On");
break;
default:
Serial.println("Read error");
}
Serial.print("FALL status:");
switch (hu.getLEDLightState(hu.eFALLLed)) {
case 0:
Serial.println("Off");
break;
case 1:
Serial.println("On");
break;
default:
Serial.println("Read error");
}
Serial.printf("Radar installation height: %d cm\n", hu.dmGetInstallHeight());
Serial.printf("Fall duration: %d seconds\n", hu.getFallTime());
Serial.printf("Unattended duration: %d seconds\n", hu.getUnmannedTime());
Serial.printf("Dwell duration: %d seconds\n", hu.getStaticResidencyTime());
Serial.printf("Fall sensitivity: %d \n", hu.getFallData(hu.eFallSensitivity));
Serial.println();
Serial.println();
}
void loop() {
Serial.print("Existing information:");
switch (hu.smHumanData(hu.eHumanPresence)) {
case 0:
Serial.println("No one is present");
break;
case 1:
Serial.println("Someone is present");
break;
default:
Serial.println("Read error");
}
Serial.print("Motion information:");
switch (hu.smHumanData(hu.eHumanMovement)) {
case 0:
Serial.println("None");
break;
case 1:
Serial.println("Still");
break;
case 2:
Serial.println("Active");
break;
default:
Serial.println("Read error");
}
Serial.printf("Body movement parameters:%d\n", hu.smHumanData(hu.eHumanMovingRange));
Serial.print("Fall status:");
switch (hu.getFallData(hu.eFallState)) {
case 0:
Serial.println("Not fallen");
break;
case 1:
Serial.println("Fallen");
break;
default:
Serial.println("Read error");
}
Serial.print("Stationary dwell status:");
switch (hu.getFallData(hu.estaticResidencyState)) {
case 0:
Serial.println("No stationary dwell");
break;
case 1:
Serial.println("Stationary dwell present");
break;
default:
Serial.println("Read error");
}
Serial.println();
delay(1000);
}
Result
Will check the serial port to see if anyone has fallen
Was this article helpful?
