Home CodeArduino Due Arduino Due and ADXL335 accelerometer example

Arduino Due and ADXL335 accelerometer example

by shedboy71

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 an Arduino Due

arduino due and adxl335

arduino due and adxl335

 

Code

No libraries required for this example

[codesyntax lang=”cpp”]

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 
}

[/codesyntax]

 

Output

 

Open the serial monitor and you should see something like this

83.00 86.34 85.61
88.28 77.76 76.67
90.69 75.47 74.36
90.54 75.32 74.51
35.20 12.95 21.04
36.41 15.09 21.91
29.48 11.23 19.17
43.50 15.24 18.74
19.52 2.79 34.59
35.51 14.09 22.77
35.66 14.24 22.48

 

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

Share

You may also like