This project harnesses the capabilities of the DFRobot mmWave sensor alongside the Beetle ESP32-C6 to capture and visualize heart and respiratory rates. Utilizing a Python script for data processing and display, it stands as an excellent venture for enthusiasts in health monitoring and IoT applications.
Components Needed- 🛠️ DFRobot mmWave Sensor
- 🔌 Beetle ESP32-C6
- 🔋 USB Cable
- 🔧 Breadboard and Jumper Wires
- 💻 Computer with Arduino IDE and Python installed
JLCPCB is a leading PCB prototype and fabrication manufacturer. Here’s why you should consider them for your next project:
Fast Turnaround: JLCPCB offers rapid PCB prototyping with build times as short as 24 hours. Whether you’re iterating on designs or need quick prototypes, they’ve got you covered.
Low Cost: Their pricing starts from just $2 for 1-4 layer PCBs (100x100mm size). Plus, they provide competitive rates for higher-layer counts.
Advanced Smart Factories: JLCPCB leverages fully automatic equipment and smart factories, ensuring both efficiency and quality.
PCB Assembly Services: Need assembly? JLCPCB offers PCB assembly starting at $8 for 5 PCs. They have over 560,000 in-stock parts and provide free DFM file checks.
Flex PCBs and Mechatronic Parts: They support flexible PCBs and offer mechatronic parts with cost savings of up to 68%.
Quality Assurance: Certified to ISO 9001:2015, ISO 14001:2015, and IPC-6012E standards, JLCPCB guarantees industry benchmarks.
Explore their services and experience the power of JLCPCB’s integrated solutions! 🚀
JLCPCB is Trusted by 5.4M Engineers Worldwide! Get a High-quality PCB Prototype for Just $2! Sign up to Get $80 Coupons: https://jlcpcb.com/?from=pradeep
Step 1: Setting Up the HardwareConnect the mmWave Sensor to the Beetle ESP32-C6:
- VCC to 5V on the Beetle ESP32-C6
- GND to GND on the Beetle ESP32-C6
- TX to RX on the Beetle ESP32-C6
- RX to TX on the Beetle ESP32-C6
Power the Beetle ESP32-C6:
- Connect the Beetle ESP32-C6 to your computer using a USB cable. 🔌
Download and Install the Arduino IDE:
- Visit the Arduino Software page and download the IDE for your operating system. 💻
- Install the Arduino IDE following the instructions for your OS.
Add the ESP32 Board Manager:
- Open the Arduino IDE and go to
File > Preferences
. - In the “Additional Board Manager URLs” field, add the following URL:
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
- Open Boards Manager: Go to Tools > Board > Boards Manage 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 to which your ESP32 board is connected.
- Open Arduino IDE and go to Sketch > Include Library > Manage Libraries.
Search for and install the following libraries
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.
Then we need only the Heart and respiration rate in our plot, so we modify the code as needed.
#include "DFRobot_HumanDetection.h"
DFRobot_HumanDetection hu(&Serial1);
void setup() {
Serial.begin(115200);
mySerial.begin(115200);
Serial1.begin(115200, SERIAL_8N1, /*rx =*/17, /*tx =*/16);
while (hu.begin() != 0) {
delay(1000);
}
while (hu.configWorkMode(hu.eSleepMode) != 0) {
Serial.println("error!!!");
delay(1000);
}
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.println();
Serial.println();
}
void loop() {
Serial.print("Respiration rate: ");
Serial.println(hu.getBreatheValue());
Serial.print("Heart rate: ");
Serial.println(hu.gitHeartRate());
delay(200);
}
Step 4: Setting Up the Python EnvironmentInstall Python:Download and install Python from the official website.
Install Required Libraries:
Open a terminal or command prompt and run the following commands:
pip install pyserial
pip install matplotlib
Step 5: Writing the Python ScriptCreate a New Python Script:Open your preferred text editor or IDE and create a new Python script (e.g., visualize_health.py
). 📝
Write the Python Code:
import serial
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
from matplotlib.widgets import TextBox
# Set up the serial port
ser = serial.Serial('COM18', 115200) # Replace 'COM10' with your COM port and set the correct baud rate
# Initialize variables
A = None
B = None
xs_A = []
ys_A = []
xs_B = []
ys_B = []
serial_data = ""
# Set up the plots
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 8))
axbox = plt.axes([0.1, 0.01, 0.8, 0.05]) # Position for the text box
text_box = TextBox(axbox, 'Serial Data', initial="")
def smooth_curve(x, y):
x_smooth = np.linspace(min(x), max(x), 300)
y_smooth = np.interp(x_smooth, x, y)
return x_smooth, y_smooth
def animate(i, xs_A, ys_A, xs_B, ys_B):
global serial_data
if ser.in_waiting > 0:
line = ser.readline().decode('utf-8').strip()
print(f"Received: {line}")
serial_data = line # Update serial_data with the current line only
# Parse the data
if "Respiration rate: " in line:
A = int(line.split(':')[1].strip())
xs_A.append(len(xs_A))
ys_A.append(A)
elif "Heart rate: " in line:
B = int(line.split(':')[1].strip())
xs_B.append(len(xs_B))
ys_B.append(B)
# Limit lists to 100 items
xs_A = xs_A[-30:]
ys_A = ys_A[-30:]
xs_B = xs_B[-30:]
ys_B = ys_B[-30:]
# Clear and plot the data for A
ax1.clear()
ax1.set_facecolor('#000000') # Set the background color to a dark gray
if len(xs_A) > 1:
x_smooth_A, y_smooth_A = smooth_curve(xs_A, ys_A)
ax1.plot(x_smooth_A, y_smooth_A, color='red', linestyle='-', marker='.', label='Respiration Rate', linewidth=0.1)
ax1.fill_between(x_smooth_A, y_smooth_A, color='red', alpha=0.2)
ax1.set_title('Respiration Monitoring', fontsize=16)
ax1.set_xlabel('Time', fontsize=14)
#ax1.set_ylabel('', fontsize=14)
ax1.legend(loc='upper left', fontsize=12)
ax1.grid(True, linestyle='--', alpha=0.5)
ax1.set_ylim([0, 50]) # Set the y-axis limit to 200
# Clear and plot the data for B
ax2.clear()
ax2.set_facecolor('#000000') # Set the background color to a dark gray
if len(xs_B) > 1:
x_smooth_B, y_smooth_B = smooth_curve(xs_B, ys_B)
ax2.plot(x_smooth_B, y_smooth_B, color='blue', linestyle='-', marker='.', label='Heart Rate', linewidth=0.1)
ax2.fill_between(x_smooth_B, y_smooth_B, color='blue', alpha=0.2)
ax2.set_title('Heart Rate Monitoring', fontsize=16)
ax2.set_xlabel('Time', fontsize=14)
# ax2.set_ylabel('Blood Oxygen Level (%)', fontsize=14)
ax2.legend(loc='upper left', fontsize=12)
ax2.grid(True, linestyle='--', alpha=0.5)
ax2.set_ylim([0, 125]) # Set the y-axis limit to 100
# Update the text box with the current serial data
text_box.set_val(serial_data)
# Set up the animation
ani = animation.FuncAnimation(fig, animate, fargs=(xs_A, ys_A, xs_B, ys_B), interval=1000)
# Show the plot
plt.tight_layout()
plt.show()
Run the Python Script:Save the script and run it using the command:
python visualize_health.py
We need to wait sometime to get the heart and respiration rates. Make sure that the sensor is placed straight to the chest.
Here is the response once we get the data from the sensor.
In this tutorial, we have explored how to use the DFRobot mmWave sensor and Beetle ESP32-C6 to create a real-time health monitoring system. We set up the hardware, wrote the necessary Arduino code to read data from the sensor, and used a Python script to visualize heart and respiratory rates. This project demonstrates the powerful capabilities of combining IoT hardware with Python for data visualization and health monitoring applications. 🩺📊
Feel free to ask if you have any questions or need further assistance! 😊
Comments
Please log in or sign up to comment.