Pages: [1]   Go Down
Author Topic: interfacing accelerometer using arduino uno  (Read 311 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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()
{
  Serial.begin(9600);
}
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(xdist);
  Serial.print("\t");
  Serial.print("yaxis cm=");
  Serial.print(ydist);
  Serial.print("\t");
  Serial.print("zaxis cm=");
  Serial.print(zdist);
  Serial.print("\n");
 }
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
Logged

Offline Offline
Sr. Member
****
Karma: 4
Posts: 329
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?"
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: