My Blog

My WordPress Blog

My Blog

My WordPress Blog

Fitness Tracker

Hardware Components

  1. Microcontroller: Arduino Uno or Raspberry Pi
  2. Sensors:
    • Accelerometer (e.g., MPU6050)
    • Heart rate sensor (e.g., MAX30100)
  3. Display (optional): OLED display
  4. Power Supply: Battery or USB power source
  5. Bluetooth Module: HC-05 for communication with a mobile app (if using Arduino)

Software Components

  1. Arduino IDE: For programming the microcontroller
  2. Mobile App: Could be a simple web app or a native app using frameworks like React Native.

Sample Code for Arduino

Setting Up the Accelerometer

cppCopy code#include <Wire.h>
#include <MPU6050.h>

MPU6050 mpu;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  mpu.initialize();
  if (!mpu.testConnection()) {
Serial.println("MPU6050 connection failed");
} } void loop() { int16_t ax, ay, az; mpu.getAcceleration(&ax, &ay, &az); Serial.print("Acceleration X: "); Serial.print(ax); Serial.print(" Y: "); Serial.print(ay); Serial.print(" Z: "); Serial.println(az); delay(1000); }

Setting Up the Heart Rate Sensor

cppCopy code#include <Wire.h>
#include <MAX30100_PulseOximeter.h>

MAX30100_PulseOximeter pox;

void setup() {
  Serial.begin(9600);
  pox.begin();
}

void loop() {
  pox.update();
  Serial.print("Heart Rate: ");
  Serial.println(pox.getHeartRate());
  delay(1000);
}

Mobile App Example (Using React Native)

You can use libraries like react-native-bluetooth-serial to connect to your Arduino.

Basic Setup

bashCopy codenpx react-native init FitnessTracker
cd FitnessTracker
npm install react-native-bluetooth-serial

Sample Code for App

javascriptCopy codeimport React, { useEffect, useState } from 'react';
import { View, Text, Button } from 'react-native';
import BluetoothSerial from 'react-native-bluetooth-serial';

const App = () => {
  const [data, setData] = useState('');

  useEffect(() => {
BluetoothSerial.connect('DEVICE_MAC_ADDRESS')
  .then((res) =&gt; {
    console.log('Connected', res);
  })
  .catch((err) =&gt; console.log(err));
BluetoothSerial.on('data', (data) =&gt; {
  setData(data);
});
return () =&gt; {
  BluetoothSerial.disconnect();
};
}, []); return (
&lt;View&gt;
  &lt;Text&gt;Received Data: {data}&lt;/Text&gt;
  &lt;Button title="Connect" onPress={() =&gt; {/* Add connection logic */}} /&gt;
&lt;/View&gt;
); }; export default App;

Next Steps

  1. Data Logging: Store data on a cloud server or local storage for long-term tracking.
  2. Visualization: Create graphs to visualize progress over time.
  3. User Interface: Improve the mobile app interface for better user experience.
Fitness Tracker

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top