Hardware Components
- Microcontroller: Arduino Uno or Raspberry Pi
- Sensors:
- Accelerometer (e.g., MPU6050)
- Heart rate sensor (e.g., MAX30100)
- Display (optional): OLED display
- Power Supply: Battery or USB power source
- Bluetooth Module: HC-05 for communication with a mobile app (if using Arduino)
Software Components
- Arduino IDE: For programming the microcontroller
- 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) => {
console.log('Connected', res);
})
.catch((err) => console.log(err));
BluetoothSerial.on('data', (data) => {
setData(data);
});
return () => {
BluetoothSerial.disconnect();
};
}, []);
return (
<View>
<Text>Received Data: {data}</Text>
<Button title="Connect" onPress={() => {/* Add connection logic */}} />
</View>
);
};
export default App;
Next Steps
- Data Logging: Store data on a cloud server or local storage for long-term tracking.
- Visualization: Create graphs to visualize progress over time.
- User Interface: Improve the mobile app interface for better user experience.
Leave a Reply