Hi everyone, I want to make pedometer with ADXL345 and ARDUINO UNO board. I am using ADXL345 with Full resolution
Wire.beginTransmission(ADXL345); // Start communicating with the device
Wire.write(0x31);
Wire.write(0x0B);
Wire.endTransmission();
and
Wire.beginTransmission(ADXL345);
Wire.write(0x2C);
Wire.write(0x09); //For low power 000x x pin set to 1 /1001 determine Hz
Wire.endTransmission();
According to datasheet, I am using it with Output Data Rate = 50 and Bandwidth (Hz) =25 .
So data rate 20 ms I guess. When I checked the pedometer codes, they use like
delay(200);
delay(50);
How can I determine good delay ?
My codes full code here
void loop() {
// === Read acceleromter data === //
Wire.beginTransmission(ADXL345);
Wire.write(0x32); // Start with register 0x32 (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(ADXL345, 6, true); // Read 6 registers total, each axis value is stored in 2 registers
X_out = ( Wire.read() | Wire.read() << 8); // X-axis value
X = X_out /256; //For a range of +-2g, we need to divide the raw values by 256, according to the datasheet
Y_out = ( Wire.read() | Wire.read() << 8); // Y-axis value
Y = Y_out /256;
Z_out = ( Wire.read() | Wire.read() << 8); // Z-axis value
Z = Z_out /256;
ave = sqrt((X - xave) * (X - xave) + (Y - yave) * (Y - yave) + (Z - zave) * (Z - zave));// ave = sqrt(x*x + y*y +z*z);
if(sampling == 0)
{
maxave = ave;
minave = ave;
}
else if(maxave < ave)
{
maxave = ave;
}
else if(minave > ave)
{
minave = ave;
}
sampling++;
if(sampling >= 20)
{
threshold = (maxave + minave) / 2 + 0.3;
sampling = 0;
}
delay(200);

Red line = threshold value and blue line steps of mine. I made 14 steps in this graph. If we count the peak values, it is equal 16 I guess.
I have 2 question.
How can I determine good delay ?
threshold = (maxave + minave) / 2 + 0.3;
As you can see, I am using a fixed value (0.3). How can I make this dynamic ? If I don't choose a fixed value, anyone can use it.