I am working with the ADXL335 using the Arduino pro mini (3.3V 8Mhz). I need help on how to calculate acceleration using the values, not tilt! I am getting correct values for z=1g, but the same for z=-1g gives me erroneous values. Please help me! I keep my sensor steady at x=0g, y=0g, z=1g while uploading the code on the arduino to obtain caliberation values.
int q[6];
int xaxis, yaxis, zaxis;
int sv1 = 0;
int sv2 = 0;
int sv3 = 0;
float ov1,ov2,ov3;
void setup()
{
Serial.begin(115200);
caliberate(q);
}void loop() {
sv1 = analogRead(A0);
delay(1);
xaxis=sv1-q[0]+q[1];
ov1 = map1(xaxis, 0, 1023, -39.8, 39.8 );sv2 = analogRead(A1);
yaxis=sv2-q[2]+q[3];
ov2 = map1(yaxis, 0, 1023, -39.8, 39.8 );
delay(1);sv3 = analogRead(A2);
zaxis=sv3-q[4]+q[5];
ov3 = map1(zaxis, 0, 1023, -39.8, 39.8 );Serial.print("Xsensor1 = " );
Serial.print(xaxis);
Serial.print("\t");Serial.print("into acc. =");
Serial.print(ov1);
Serial.print("\t");Serial.print("Ysensor2 = " );
Serial.print(yaxis);
Serial.print("\t");
Serial.print("into acc. =");
Serial.print(ov2);
Serial.print("\t");Serial.print("Zsensor3 = " );
Serial.print(zaxis);
Serial.print("\t");Serial.print("into acc. =");
Serial.print(ov3);
Serial.print("\n");delay(1000);
}
void caliberate ( int w[])
{
int x1,y1,z1;
x1=analogRead(A0);
y1=analogRead(A1);
z1=analogRead(A2);if (x1!=511 && y1!=511 & z1!=682) {
if (x1>511)
{
w[0]=x1-511;
w[1]=0;
}
else if (x1<511)
{
w[1]=511-x1;
w[0]=0;
}
if (y1>511)
{
w[2]=y1-511;
w[3]=0;
}
else if (y1<511)
{
w[3]=511-y1;
w[2]=0;
}
if (z1>682)
{
w[4]=z1-682;
w[5]=0;
}
else if (z1<682)
{
w[5]=682-z1;
w[4]=0;
}
}}
float map1(int x, int in_min, int in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}