Hi everyone! I'm working on a project using MPU6050 IMU Sensors. For my project focused on spine positioning. I attached the sensors from the cervical down to lumbar. I need data showing the results of the XYZ position of the patient's spine in meters. Any help or references would be greatly appreciated!
#include <Wire.h>
#include <MPU6050.h> // Include the MPU6050 library
MPU6050 imu; // Create an instance of the MPU6050
// Constants
const float dt = 0.1; // Time step in seconds
const float threshold = 0.05; // Threshold to detect if the sensor is stationary
// Variables
int16_t raw_ax, raw_ay, raw_az; // Raw acceleration values
float ax, ay, az; // Converted acceleration values
float vx = 0, vy = 0, vz = 0; // Velocity values
float x = 0, y = 0, z = 0; // Position values
void setup() {
Serial.begin(9600);
Wire.begin();
imu.initialize();
if (!imu.testConnection()) {
Serial.println("IMU connection failed");
while (1); // Stop if IMU is not connected
}
}
void loop() {
// Read raw accelerometer data
imu.getAcceleration(&raw_ax, &raw_ay, &raw_az);
// Convert raw data to g's (1 g = 9.8 m/s²)
ax = raw_ax / 16384.0;
ay = raw_ay / 16384.0;
az = raw_az / 16384.0;
// Subtract gravity if the sensor is relatively stationary
if (abs(ax) < threshold && abs(ay) < threshold && abs(az - 1.0) < threshold) {
ax = 0;
ay = 0;
az = 0;
vx = 0; vy = 0; vz = 0; // Reset velocity if nearly stationary
} else {
// Update velocity by integrating acceleration
vx += ax * dt;
vy += ay * dt;
vz += (az - 1.0) * dt; // Subtract gravity component (assuming z-axis is vertical)
}
// Update position by integrating velocity
x += vx * dt;
y += vy * dt;
z += vz * dt;
// Print position data to Serial Monitor
Serial.print("Position X: ");
Serial.print(x);
Serial.print(" m, ");
Serial.print("Y: ");
Serial.print(y);
Serial.print(" m, ");
Serial.print("Z: ");
Serial.print(z);
Serial.println(" m");
// Delay for a while before the next loop iteration
delay(100); // Delay in milliseconds (100 ms = 0.1 s)
}
I used this code before but the results show the values keep increasing with large numbers. I want it to be start with 0 when its not moving and reset to 0 when its stop moving. But I didn't get it.
To my best knowledge, the 6050 is an accelerometer, not a position sensor.
If you don't mind, can you suggest what sensors are suitable for positioning purposes? Or if I still want to use the 6050, is there any other way to determine the difference in the position or posture of the spine whether it is normal or not.
Welcome to the forum.
The LiDAR scanner from a iPhone can scan the back of a person, but you need X-ray photos to say something about the posture of the spine.
To calculate the position from a single MPU-6050 is possible for maybe a few minutes. It is done by trying to keep track of the sensor values with calculations. But the motions may not be too fast and not too small.
However, for your project it will probably be impossible. I see too many problems: wrong counterfeit sensor, wrong library, motions are too small, the I2C bus is too slow, initializing the starting position might take half an hour, and so on.
Fun fact: It is possible to connect many MPU-6050 sensors to a single board: https://wokwi.com/projects/394777263927329793 But that is a completely different world than your project.
Not sure to understand your problem, but if you want to attach this sensor to 'the spine of a person' and analyze the posture while waking ( for example ) I think you need an inclinometer ( 3 axis ).
Also having more than one sensor to help reconstruct the whole spine movements...
But then I don't understand why it should auto zero when the person stops, so what is the goal?
Hi everyone,
I’m working on a spine posture capture system using MPU6050 IMU sensors paired with an Arduino Uno for rehabilitation purposes. The system aims to monitor posture conditions like kyphosis, scoliosis, and normal posture.
I’ve written the following code to get sensor readings, but I’m facing some challenges:
- Calibrating the IMU sensors for accurate posture detection.
- Interpreting the sensor data (e.g., pitch, roll) to classify the posture condition correctly.
Here’s the code I’ve been working with:
#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!");
while (1);
}
Serial.println("MPU6050 connection successful!");
}
void loop() {
int16_t ax, ay, az;
int16_t gx, gy, gz;
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
float Ax = ax / 16384.0;
float Ay = ay / 16384.0;
float Az = az / 16384.0;
float Gx = gx / 131.0;
float Gy = gy / 131.0;
float Gz = gz / 131.0;
float pitch = atan2(-Ax, sqrt(Ay * Ay + Az * Az)) * 180.0 / PI;
float roll = atan2(Ay, sqrt(Ax * Ax + Az * Az)) * 180.0 / PI;
Serial.print("Ax: "); Serial.print(Ax); Serial.print(" Ay: "); Serial.print(Ay); Serial.print(" Az: "); Serial.println(Az);
Serial.print("Pitch: "); Serial.print(pitch); Serial.print(" Roll: "); Serial.println(roll);
if (pitch > 15) {
Serial.println("Kyphosis detected");
} else if (roll > 10 || roll < -10) {
Serial.println("Scoliosis detected");
} else {
Serial.println("Normal posture");
}
delay(500);
}
And these are the results I got:
Ax: 0.00 Ay: 0.03 Az: 1.04
Pitch: -0.19 Roll: 1.73
Normal posture
(When I didn't move the sensor)
Ax: 0.05 Ay: -0.99 Az: 0.03
Pitch: -3.16 Roll: -86.33
Scoliosis detected
(When the box upside down)
Ax: 0.04 Ay: 0.99 Az: 0.02
Pitch: -2.43 Roll: 87.30
Scoliosis detected
(When the box upside down, the other way around)
Ax: -0.96 Ay: -0.01 Az: -0.01
Pitch: 88.97 Roll: -0.84
Kyphosis detected
(Turn the box to the right)
Ax: 1.04 Ay: -0.00 Az: 0.10
Pitch: -84.28 Roll: -0.01
Normal posture
(Turn the box to the left)
I am currently facing an issue where, when using multiple sensors (one for each region of the spine), the results are not consistent, and I often receive zero values. As someone who is still learning how to handle Arduino projects effectively, I would greatly appreciate any help with:
- Calibrating multiple sensors to ensure accurate readings.
- Interpreting the pitch and roll data in order to reliably classify posture conditions.
If anyone has experience with sensor calibration or data interpretation in this context, I would be truly grateful for any advice, example code, or resources you could share.
Thank you very much for your time and assistance, and I apologize if I’ve made any mistakes or missed any details in my question!
There are numerous google hits for IMU devices , example code etc .
What have you done thus far and how will an IMU device help ?
Posture suggests position , can’t see how a IMU helps with that
IMUs can be used to measure the tilt angles from vertical, which would likely be the only useful contribution to the project.
I have merged your topics due to them having too much overlap on the same subject matter @HidekiAiba .
In the future, please only create one topic for each distinct subject matter and be careful not to cause them to converge into parallel discussions.
The reason is that generating multiple threads on the same subject matter can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.
Thanks in advance for your cooperation.
These are not correct equations for standard Euler angles and you may have difficulty to interpret the results.
Would you mind sharing the correct equations for standard Euler angles?
One set of correct equations (depending on which of the six Euler angle definitions is chosen) is described in this tutorial.
You may find this project relevant: Double Jump Electric
Thank you so much for kindly sharing this. I really appreciate it!
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.