Example Code for Arduino-Read Accelerometer Data

Hardware Preparation

Wiring Diagram

MMA7260 Connection Diagram

The diagram consist of the following items:

Sample Code

For Arduino

//Arduino Sample Code
//Developed by DFRobot.com
//Last Modified 30/11/2011
//Version 1.0
void setup()
{
  Serial.begin(19200); // 19200 bps
}
void loop()
{
      int x,y,z;
      x=analogRead(0);
      y=analogRead(1);
      z=analogRead(2);
      Serial.print("x= ");
      Serial.print(x ,DEC);
      Serial.print(',');
      Serial.print("y= ");
      Serial.print(y ,DEC);
      Serial.print(',');
      Serial.print("z= ");
      Serial.println(z ,DEC);
      delay(100);
}

Was this article helpful?

TOP