# How to calculate running speed using accelerometer sensor ?

Hi guys,

I am working with accelerometer sensor. I would like to turn speed value that you got. what should I do ? can you help me

Me code;

 #include<Wire.h>
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;

void setup(){
Wire.begin();
Wire.write(0x6B);  // PWR_MGMT_1 register
Wire.write(0);     // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
Serial.begin(57600);
}
void loop(){
Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr,14,true);  // request a total of 14 registers
Serial.print("AcX = "); Serial.print(AcX);
Serial.print(" | AcY = "); Serial.print(AcY);
Serial.print(" | AcZ = "); Serial.print(AcZ);
Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53);  //equation for temperature in degrees C from datasheet
Serial.print(" | GyX = "); Serial.print(GyX);
Serial.print(" | GyY = "); Serial.print(GyY);
Serial.print(" | GyZ = "); Serial.println(GyZ);

Serial.print("HIZ:");Serial.println(sqrt( AcX^2 + AcY^2 + AcZ^2));

delay(333);
}


And me values Arduino com;

AcX = 0 | AcY = 0 | AcZ = 0 | Tmp = 36.53 | GyX = 0 | GyY = 0 | GyZ = 0
HIZ:1.41
AcX = 1112 | AcY = 15716 | AcZ = -3776 | Tmp = 26.27 | GyX = -624 | GyY = 2157 | GyZ = -1428
HIZ:nan
AcX = 976 | AcY = 15700 | AcZ = -4280 | Tmp = 26.46 | GyX = -493 | GyY = 266 | GyZ = -177
HIZ:nan
AcX = 900 | AcY = 15660 | AcZ = -4176 | Tmp = 26.46 | GyX = -522 | GyY = 287 | GyZ = -157
HIZ:nan

edit retag close merge delete

2

I didn't read through your code, but just giving a heads up that calculating velocity by integrating acceleration from an accelerometer will not be accurate at all. Here are some sources: http://www.chrobotics.com/library/acc... , http://stackoverflow.com/questions/782

( 2015-12-14 07:55:57 -0600 )edit

Only way to do this that I can think about is to wear the accelerometer and run with many different speeds, thus collecting a lot of data. Then you can try applying some motion segmentation algorithms to recognize one running stride, isolate this data and do some machine learning to learn speed.

( 2015-12-14 09:01:39 -0600 )edit

Opps, my second link was cut short and I can't edit it. Here it is: http://stackoverflow.com/questions/78...

( 2015-12-14 09:25:57 -0600 )edit

Okey, I will try thanks.

( 2015-12-15 02:49:16 -0600 )edit

First: This is not ros-related, but Arduino stuff. Second, there are far better approaches to do this. Accelerometer data is not suitable to be integrated. You will have to have some kind of reference system if you wanna do that. For intermediate precision you could use an GPS-based approach

( 2018-08-22 06:40:35 -0600 )edit

Another way to approach is to permanently meassure the distance between your feets and also count the steps that you're doing.

( 2018-08-22 06:44:39 -0600 )edit