hi everyone..
I have MMA7361 accelerometer.I try many of code.but I cannot measure acceleration truly. please help me .. can you give me some example code.
const int XPin = A0; // X
const int YPin = A1; // Y
const int ZPin = A2; // Z
const int X0 = 337; // Adjust to raw 0g value for X
const int Y0 = 337; // Adjust to raw 0g value for Y
const int Z0 = 337; // Adjust to raw 0g value for Z
// Sensitivity: Volts per G
const float Xsens = 0.800 * 5.0 / 1023.0; // Adjust to get 1.0 at 1g
const float Ysens = 0.800 * 5.0 / 1023.0;
const float Ysens = 0.800 * 5.0 / 1023.0;
float Xg = 0;
float Yg = 0;
float Zg = 0;
void setup() {Serial.begin(9600);}
void loop() {
unsigned int Xraw = analogRead(XPin);
unsigned int Yraw = analogRead(YPin);
unsigned int Zraw = analogRead(ZPin);
Xg = (Xraw - X0) * Xsens * 5.0 / 1023.0;
Yg = (Yraw - Y0) * Ysens * 5.0 / 1023.0;
Zg = (Zraw - Z0) * Zsens * 5.0 / 1023.0;
Serial.print("Xraw=");
Serial.print(Xraw);
Serial.print(" Xg=");
Serial.print(Xg);
Serial.print(" Yraw=");
Serial.print(Yraw);
Serial.print(" Yg=");
Serial.print(Yg);
Serial.print(" Zraw=");
Serial.print(Zraw);
Serial.print(" Zg=");
Serial.println(Zg);
delay(200);
}
thank you very much.. ? will try