Go Down

Topic: MMA7361 accelerometer problem (Read 594 times) previous topic - next topic

nazrdogan

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.



johnwasser

Code: [Select]

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);

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

nazrdogan

thank you very much.. ? will try

Go Up