diadjiMonsieur-ugurZoranKarimQorar95
Published

Fitbody

The FITBODY project aims to develop a Bluetooth-connected system capable of measuring physiological data.

IntermediateWork in progress64
Fitbody

Things used in this project

Hardware components

Adafruit MMA8451
×1
ILE-BIO1
×1
FireBeetle ESP32 IOT Microcontroller (Supports Wi-Fi & Bluetooth)
DFRobot FireBeetle ESP32 IOT Microcontroller (Supports Wi-Fi & Bluetooth)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Android Studio
Android Studio
KiCad
KiCad

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
PCB Holder, Soldering Iron
PCB Holder, Soldering Iron

Story

Read more

Custom parts and enclosures

Code for the app

Code

ESP32 Code

Arduino
The following code measures acceleration and SpO2, then transmits the data via BLE.
#include <Wire.h>
#include <Adafruit_MMA8451.h>
#include <Adafruit_Sensor.h>
#include <math.h>
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>

// --- Sensor Initialization ---
Adafruit_MMA8451 mma = Adafruit_MMA8451();
#define RED_LED_PIN 25
#define IR_LED_PIN 26
#define PHOTO_DIODE_PIN 34

// --- BLE Configuration ---
#define SERVICE_UUID        "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
BLEServer* pServer = NULL;
BLECharacteristic* pCharacteristic = NULL;
bool deviceConnected = false;

void setup() {
  Serial.begin(115200);
  pinMode(RED_LED_PIN, OUTPUT);
  pinMode(IR_LED_PIN, OUTPUT);
  pinMode(PHOTO_DIODE_PIN, INPUT);
  
  if (!mma.begin()) {
    Serial.println("Error: MMA8451 not detected");
    while (1);
  }
  mma.setRange(MMA8451_RANGE_2_G);
  
  // --- BLE Initialization ---
  BLEDevice::init("ESP32_Sensor");
  pServer = BLEDevice::createServer();
  pCharacteristic = pServer->createService(SERVICE_UUID)->createCharacteristic(
                      CHARACTERISTIC_UUID,
                      BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_NOTIFY
                    );
  pCharacteristic->addDescriptor(new BLE2902());
  pServer->start();
  BLEDevice::getAdvertising()->addServiceUUID(SERVICE_UUID);
  BLEDevice::getAdvertising()->start();
}

void loop() {
  sensors_event_t event;
  mma.getEvent(&event);
  float norm = sqrt(event.acceleration.x * event.acceleration.x +
                     event.acceleration.y * event.acceleration.y +
                     event.acceleration.z * event.acceleration.z);
  
  float spO2 = measureSpO2();
  
  String data = "Acc: " + String(norm) + " m/s2, SpO2: " + String(spO2) + "%";
  pCharacteristic->setValue(data.c_str());
  pCharacteristic->notify();
  delay(500);
}

float measureSpO2() {
  digitalWrite(RED_LED_PIN, HIGH);
  digitalWrite(IR_LED_PIN, LOW);
  delay(5);
  int redValue = analogRead(PHOTO_DIODE_PIN);

  digitalWrite(RED_LED_PIN, LOW);
  digitalWrite(IR_LED_PIN, HIGH);
  delay(5);
  int irValue = analogRead(PHOTO_DIODE_PIN);
  
  return 110 - 25 * (redValue / (float)irValue);
}

Credits

diadji
2 projects • 1 follower
Monsieur-ugur
1 project • 1 follower
Zoran
0 projects • 1 follower
KarimQorar95
0 projects • 0 followers
Thanks to KarimQorar.

Comments