Example Code for Arduino-Presence-Respiration-HeartRate

This article provides an example code for using the C1001 Millimeter Wave Human Detection Sensor with an ESP32 board to detect human presence, respiration, and heart rate. It includes hardware and software preparation, wiring diagrams, and sample code to facilitate setup and execution.

Hardware Preparation

Software Preparation

Wiring Diagram

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 respiration rate and heart rate, the sensor should be placed 1.5m in front of the human body and the sensor should be directly facing the chest of the detected person.

Sample Code

/**!
 * @file sleep.ino
 * @brief This is an example of the C1001 mmWave Human Detection Sensor detecting the presence of people and their respiration and heart rates.
 * @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.eSleepMode) != 0) {
    Serial.println("error!!!");
    delay(1000);
  }
  Serial.println("Work mode switch successful");

  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");
  }

  hu.configLEDLight(hu.eHPLed, 1);  // Set HP LED switch, it will not light up even if the sensor detects a person when set to 0.
  hu.sensorRet();                   // Module reset, must perform sensorRet after setting data, otherwise the sensor may not be usable

  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.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.printf("Respiration rate:%d\n", hu.getBreatheValue());
  Serial.printf("Heart rate:%d\n", hu.getHeartRate());
  Serial.println();
  delay(1000);
}

Result

Heart rate and respiratory rate will be output via serial port.

Example 1 Result

Was this article helpful?

TOP