Go Down

Topic: interfacing accelerometer using arduino uno (Read 425 times) previous topic - next topic


im trying to calculate the distance measured from a starting point. i have interfaced the accelerometer usng arduino uno and obtained the reading on all 3 axes. i have considered the acceleration reading to be constant over the sampling interval and used that to calculate distance. this is the code.
float xdist;
float ydist;
float zdist;
const float g = 9.8;
const float xysampt = (1/6000);
const float zsampt = (1/3400);
void setup()
void loop()
  int xip=analogRead(A0);
  int yip=analogRead(A2);
  int zip=analogRead(A4);
  int Xin= xip-356;
  int Yin= yip-383;
  int Zin= zip-464;
  float xvolt= (Xin*5)/1024;
  float yvolt= (Yin*5)/1024;
  float zvolt= (Zin*5)/1024;
  float xacc = (xvolt*g*100)/0.8;
  float yacc = (yvolt*g*100)/0.8;
  float zacc = (zvolt*g*100)/0.8;
  float xvel = xacc * xysampt;
  float yvel = yacc * xysampt;
  float zvel = zacc * zsampt;
  float xdisp = xvel * xysampt;
  float ydisp = yvel * xysampt;
  float zdisp = zvel * zsampt;
  xdist += xdisp;
  ydist += ydisp;
  zdist += zdisp;
  Serial.print("xaxis cm=");
  Serial.print("yaxis cm=");
  Serial.print("zaxis cm=");
im getting the acceleration reading from the accelerometer. but im not getting the distance reading from this program. please tell me what my mistake could be


hi, i'm also a newbie trying to use an accelerometer.
as far as i know, i don't think it can measure distance - just the position it is in, relative to vertical (upright), horizontal(level) and "falling ?"


it doesnt measure distance.. just the instantaneous acceleration.. im trying to calculate the distance using that.

Go Up