Linkit One and ADXL335 accelerometer example

The ADXL335 is a small, thin, low power, complete 3-axis accelerometer with signal conditioned voltage outputs. The product measures acceleration with a minimum full-scale range of ±3 g. It can measure the static acceleration of gravity in tiltsensing applications, as well as dynamic acceleration resulting from motion, shock, or vibration.

The user selects the bandwidth of the accelerometer using the CX, CY, and CZ capacitors at the XOUT, YOUT, and ZOUT pins. Bandwidths can be selected to suit the application, with a range of 0.5 Hz to 1600 Hz for X and Y axes, and a range of 0.5 Hz to 550 Hz for the Z axis.

Here is a typical module that makes it easy to work with the ADXL335

Features:

Name: ADXL335 module (triaxial accelerometer analog output)
Model: GY-61
Power supply :3-5v
Analog X, Y, Z three-axis output

 
Schematic

The following layout shows how to wire the ADXL335 module up to a Linkit One

 

 

Code

 

const int xpin = A0; // x-axis of the accelerometer
const int ypin = A1; // y-axis
const int zpin = A2; // z-axis

void setup()
{
Serial.begin(9600);
}

void loop()
{
int x = analogRead(xpin); //read from xpin
delay(1); //
int y = analogRead(ypin); //read from ypin
delay(1); 
int z = analogRead(zpin); //read from zpin

float zero_G = 512.0; //ADC is 0~1023 the zero g output equal to Vs/2
float scale = 102.3; //ADXL335330 Sensitivity is 330mv/g
//330 * 1024/3.3/1000
Serial.print(((float)x - 331.5)/65*9.8); //print x value on serial monitor
Serial.print("\t");
Serial.print(((float)y - 329.5)/68.5*9.8); //print y value on serial monitor
Serial.print("\t");
Serial.print(((float)z - 340)/68*9.8); //print z value on serial monitor
Serial.print("\n");
delay(1000); //wait for 1 second 
}

 

 
Output

Open the serial monitor and you should see something like this

-3.54    3.51    9.22
-3.39    -5.79    3.31
-4.75    -9.08    6.77
25.40    29.83    -3.31
-1.43    6.22    8.21
-1.58    5.79    8.50
-1.73    5.79    8.50
-1.73    5.65    8.65

 
Links
http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL335.pdf

The sensor costs under $2

GY-61 ADXL335 Module Triaxial Acceleration Gravity Angle Sensor