Harshit Chhapliyal
Published

Smart Wearable Activity Monitoring System

This project presents the development of an end-to-end smart wearable system designed to recognize and classify human physical activities.

IntermediateProtip37
Smart Wearable Activity Monitoring System

Things used in this project

Hardware components

Nucleo 144 STM32F7
ST STM32L4, STM32F7 Nucleo 144 STM32F7
×1

Software apps and online services

RT-Thread IoT OS
RT-Thread IoT OS

Story

Read more

Code

Backend Inference Service (Node.js)

JavaScript
const mqtt = require("mqtt");
const client = mqtt.connect("mqtt://broker");

let buffer = [];

client.on("connect", () => {
  client.subscribe("wearable/sensor");
});

client.on("message", (topic, message) => {
  const data = JSON.parse(message.toString());
  buffer.push(data);

  if (buffer.length >= 20) {
    const activity = classifyActivity(buffer);
    buffer = [];
    console.log("Detected Activity:", activity);
  }
});

function classifyActivity(window) {
  const variance = window.reduce((sum, d) =>
    sum + Math.abs(d.ax) + Math.abs(d.ay) + Math.abs(d.az), 0);

  if (variance < 5) return "Idle";
  if (variance < 20) return "Walking";
  return "Running";
}

Embedded Firmware (STM32 / RT-Thread)

C Header File
#include <rtthread.h>
#include <sensor.h>
#include <mqttclient.h>

#define SAMPLE_RATE_MS 100

static struct mqtt_client client;
static struct rt_sensor_data accel_data, gyro_data;

void publish_sensor_data(void)
{
    char payload[128];

    snprintf(payload, sizeof(payload),
        "{ \"ax\": %.2f, \"ay\": %.2f, \"az\": %.2f, "
        "\"gx\": %.2f, \"gy\": %.2f, \"gz\": %.2f }",
        accel_data.data.accel.x,
        accel_data.data.accel.y,
        accel_data.data.accel.z,
        gyro_data.data.gyro.x,
        gyro_data.data.gyro.y,
        gyro_data.data.gyro.z
    );

    mqtt_publish(&client, "wearable/sensor", payload);
}

void sensor_task(void *parameter)
{
    while (1)
    {
        rt_sensor_read(accel_dev, &accel_data, 1);
        rt_sensor_read(gyro_dev, &gyro_data, 1);

        publish_sensor_data();
        rt_thread_mdelay(SAMPLE_RATE_MS);
    }
}

Credits

Harshit Chhapliyal
17 projects • 4 followers
Automation and Robotics Engineering || CAD || CAM ||

Comments