lilypad arduino and lilypad adxl335 accelerometer measurement of a true angle.

Hello every1!! :slight_smile:
This is my first ever post and I am an absolute newbee to arduino...I am trying to measure true angles of the 'x' 'y' and 'z' axis at the moment what I get is only 'g' values I am a bit confused about the coding.I dont know how to convert this values to get the angle values display by the serial monitor.Would anyone please care to assist me with this. I will be ever so helpful for your help..

Cheers :~

Start here.

Do you know what a vector is?

Do you understand how to do force vector calculations?

Could you look it up and then ask your next question.

Thanks 4 ur reply.I know what a vector is.I know we have to get the resultant of all three axes. I do not have much problem understanding how it is calculated. I am kinda weak in programming.I do not know how to write the code so serial monitor will display it as a string.Any ideas?
cheers

Below is the code I am using at the moment,But I can't see anything in the serial monitor window :(...Please help!!!

Your code didn't make it into your post :disappointed_relieved:

int pwrPin=18; // not initialized in case not used
int gndPin=19; // "
int xPin=A1; // variable to set x pin
int yPin=A2; // y pin
int zPin=A3; // z pin
// self test pin, build does not use

long x, y, z; // hold raw x,y,z reading from sensor
int xAngle, yAngle, zAngle; // hold angle conversions
const int samples = 10; // number of samples for error
int readingX[samples]; // array of x samples
int readingY[samples]; // y
int readingZ[samples]; // z
int neutral = 3; // variable that will hold the deadspace for quadrants
int sensorMax = 470; // holds specification for max sensor range
int sensorMin = 550; // holds specification for min sensor range

// not sure if this will work because the pwrPin and gndPin were not initialized and since this
// only runs once........
void setup()
{
Serial.begin(9600);
pinMode(pwrPin, OUTPUT);
digitalWrite(pwrPin, HIGH);
pinMode(gndPin, OUTPUT);
digitalWrite(gndPin, LOW);
}

void loop(){
// read in (x) samples into the array
for (int i=0; i<samples; i++){
readingX = analogRead(xPin);
_ readingY = analogRead(yPin);_
_ readingZ = analogRead(zPin);
* }
// sum up all the array for averaging*
* for (int i=0; i<samples; i++){
x = x + readingX;
y = y + readingY;
z = z + readingZ;
}
// spit out the averages*

* x = x/samples;
y = y/samples;
z = z/samples;
}
// returns the quadrant that the accelerometer is indicating, quadrants start in top right and go counter clockwise*

int getTiltQuadrant(){
* if(x>=neutral && y>=neutral)return 1;
if(x>-neutral && x<neutral && y>neutral)return 2;
if(x<=neutral && y>=neutral)return 3;
if(x<=-neutral && y>-neutral && y<neutral) return 4;
if(x<-neutral && y<=-neutral) return 5;
if(x>-neutral && x<neutral && y<-neutral) return 6;
if(x>=neutral && y<=neutral) return 7;
if(x>=neutral && y>-neutral && y<neutral) return 8;
}
int getQuadrantTiltAngle(){
if (x>0 && y>0) return atan(x/y);
if (x>0 && y<0) return atan((x/y)+180);
if (x<0 && y<0) return atan((x/y)+180);
if (x<0 && y>0) return atan((x/y)+360);
}
// get the angle of the x in relation to plane*

int getXAngle(){
* xAngle = map(x, sensorMin, sensorMax, -90, 90);
Serial.print(xAngle);
return xAngle;
}
// y axis*

int getYAngle(){
* yAngle = map(y, sensorMin, sensorMax, -90, 90);
Serial.print(yAngle);
return yAngle;*_

}
// z axis
int getZAngle(){
* zAngle = map(z, 662, 355, -90, 90);*
* Serial.print(zAngle);*
* return zAngle;*

}
// setters and getters section
int getX(){
* return x;*
}
int getY(){
* return y;*
}
int getZ(){
* return z;*
}
void setXPin(int pin){
* xPin = 3;*
}
void setYPin(int pin){
* yPin = 2;*
}
void setZPin(int pin){
* zPin = 1;*
}
void setPwrPin(int pin){
* pwrPin = 18;*
}
void setGndPin(int pin){
* gndPin =19;*
}
void setNeutral(int neutral){
* neutral = neutral;*
}
void setSensorMax(int maxS){
* sensorMax = maxS;*
}
void setSenorMin(int minS){
* sensorMin = minS;*
}
* // print the sensor values:*

Nothing below loop is being called and that's where your print statements are, so there's no output.
Your averaging code isn't going to load the array as you have it.

Here's a much simpler sketch that should get you reading and seeing the data at least:

int xPin=A1;                   // variable to set x pin
int yPin=A2;                   // y pin
int zPin=A3;                   // z pin

int x, y, z;               // hold raw x,y,z reading from sensor

void setup()
{
  Serial.begin(9600);
  Serial.println("Starting");
}


void loop()
{ 
x = analogRead(xPin);
y = analogRead(yPin);
z = analogRead(zPin);
Serial.print(x);
Serial.print(" ");
Serial.print(y);
Serial.print(" ");
Serial.println(z);
delay(1000);
}

Hi there!
Thnx again.As I might have mentioned earlier,I can get the raw data(acceleration) easy...but getting angles of x,y, and z is where I am stuck at... :~

hi i want to ask..
how i can convert the raw data from ADXL 335 to distance measurement?

can i use

// convert the pulse width into acceleration
// accelerationX and accelerationY are in milli-g's:
// earth's gravity is 1000 milli-g's, or 1g.
accelerationX = ((pulseX / 10) - 500) * 8;
accelerationY = ((pulseY / 10) - 500) * 8;

then how i can convert milli-g's to m/s2

then how i can convert milli-g's to m/s2

Some context for this question are in order. But, if I understand the question, milli-gs ARE measured on meters per second squared, to the answer is that you don't need to do anything.

sir how can i convert meter per second squared to meter only? can i do integrate in arduino?

sir how can i convert meter per second squared to meter only? can i do integrate in arduino?

Yes, you can. You have to. The accelerometer gives instantaneous acceleration (change of velocity). You need to integrate that to get velocity (change of position). You have to integrate that to get position.

[to PaulS]

sir can u give me an example of coding to integrate..i'm stuck to find the the coding..