In this project, we’ll create a real-time heartbeat monitoring system using the DFRobot mmWave Sensor and Beetle ESP32 C6. The system will send alerts via Telegram, making it ideal for presence monitoring. This project is instrumental in continuous monitoring in the security field.
- DFRobot mmWave Sensor (60GHz)
- Beetle ESP32 C6
- Jumper wires
- Breadboard
- Power supply
- Telegram account and bot
Setting Up the Hardware
- Connect the mmWave Sensor to Beetle ESP32 C6:
- VCC to 5V
- GND to GND
- TX to RX
- RX to TX
- Power the Beetle ESP32 C6 using a suitable power supply.
- Visit the Arduino Software Page: Go to the Arduino Software page.
- Download andInstall the Arduino IDE: Choose the version compatible with your operating system (Windows, Mac OS X, or Linux) and download it.
- Launch the Arduino IDE: Open the Arduino IDE from your installed applications.
- Open Preferences: Go to
File > Preferences
(orArduino > Preferences
on Mac).
Add Board Manager URL: In the “Additional Board Manager URLs” field, enter the following URL:
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
You can separate other URLs with a comma if you already have other URLs.
- Open Boards Manager: Go to
Tools > Board > Boards Manager
. - Search for ESP32: In the search bar, type “ESP32”.
- Install ESP32: Find the “ESP32 by Espressif Systems” entry and click the “Install” button.
- Connect Your ESP32 Board: Plug your ESP32 board into your computer using a USB cable.
- Select the Board: Go to
Tools > Board
and select your specific ESP32 board model - Beetle ESP32 C6
- Select the Port: Go to
Tools > Port
and select the COM port that your ESP32 board is connected to.
- Open Arduino IDE and go to
Sketch > Include Library > Manage Libraries
.
Search for and install the following libraries:
WiFi
UniversalTelegramBot
First, navigate to the examples sketch and look for the Human Detection then use the basic sketch.
Next, you have to configure the UART pins as per the Beetle ESP32 C6.
Upload the code and look for the serial terminal output.
You can observe both motion and heart and respiratory data. For heart and respiratory data, the sensor should be positioned directly on the chest.
Create a Telegram Bot:
- Open Telegram and search for
BotFather
.
- Start a chat with BotFather and use the command
/newbot
to create a new bot.
- Follow the instructions to get your bot token.
Get Your Chat ID:
- Start a chat with your bot and send any message.
Look for the chat
object in the response to find your chat ID.
This is the complete sketch capable of detecting human motion and triggering a Telegram message.
#include "DFRobot_HumanDetection.h"
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h> // Universal Telegram Bot Library written by Brian Lough: https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot
#include <ArduinoJson.h>
#if defined(ARDUINO_AVR_UNO)||defined(ESP8266)
#include <SoftwareSerial.h>
#endif
#if defined(ARDUINO_AVR_UNO)||defined(ESP8266)
SoftwareSerial mySerial(/*rx =*/4, /*tx =*/5);
DFRobot_HumanDetection hu(&mySerial);
#else
DFRobot_HumanDetection hu(&Serial1);
#endif
// Replace with your network credentials
const char* ssid = "ELDRADO";
const char* password = "amazon123";
// Use @myidbot to find out the chat ID of an individual or a group
// Also note that you need to click "start" on a bot before it can
#define CHAT_ID "xxxxxxxxxxxxxxxxxxxx"
// Initialize Telegram BOT
#define BOTtoken "xxxxxxxxxxxxxxxxxxxxx" // your Bot Token (Get from Botfather)
WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);
//Checks for new messages every 1 second.
int botRequestDelay = 1000;
unsigned long lastTimeBotRan;
void setup() {
Serial.begin(115200);
#if defined(ARDUINO_AVR_UNO)||defined(ESP8266)
mySerial.begin(115200);
#elif defined(ESP32)
Serial1.begin(115200, SERIAL_8N1, /*rx =*/17, /*tx =*/16);
// Serial1.begin(115200, SERIAL_8N1, /*rx =*/20, /*tx =*/21);
#else
Serial1.begin(115200);
#endif
Serial.println("Start initialization");
// Connect to Wi-Fi
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
#ifdef ESP32
client.setCACert(TELEGRAM_CERTIFICATE_ROOT); // Add root certificate for api.telegram.org
#endif
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi..");
}
// Print ESP32 Local IP Address
Serial.println(WiFi.localIP());
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();
String welcome = "Welcome ";
welcome += "Motion Detector Activated.\n\n";
bot.sendMessage(CHAT_ID, welcome, "");
}
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.print("Body movement parameters: ");
Serial.println(hu.smHumanData(hu.eHumanMovingRange));
if (hu.smHumanData(hu.eHumanMovingRange) > 2) {
String message = "Motion Detected: Please check the status \n";
bot.sendMessage(CHAT_ID, message, ""); }
Serial.print("Respiration rate: ");
Serial.println(hu.getBreatheValue());
Serial.print("Heart rate: ");
Serial.println(hu.gitHeartRate());
Serial.println("---------------------- -");
delay(200);
}
Note: You need to update the Wi-Fi and Telegram credentials to match your own.
Once the motion status is above 2, it will trigger the Telegram Bot.
That’s it! You have successfully developed the motion detection system. Now let's check the system performance. Here is my system's working video.
Wrap-upIn this tutorial, we have explored the integration of the DFRobot mmWave sensor with an ESP32-C6 to create a sophisticated human motion detection system. We walked through the process of setting up the hardware, configuring the sensor, and writing the necessary code to detect human presence and movements. Additionally, we demonstrated how to connect this system to a Telegram Bot, enabling real-time notifications and alerts directly to your mobile device.
This project not only showcases the capabilities of the mmWave sensor in accurately detecting motion but also highlights the convenience and effectiveness of using Telegram for remote monitoring and control. By following these steps, you can build a reliable and interactive motion detection system for various applications, from home automation to security systems
Comments