
The three-axis accelerometer measures acceleration in the X, Y, and Z axes.
When you need to measure acceleration, orientation, or physical movement of the sensor.
This sensor works by housing a Micro Electro-Mechanical System (MEMS) inside of the microchip. Springs suspend floating fingers in between fixed fingers. The floating fingers can move back and forth on one axis. Deflection in one direction or the other causes a change in capacitance between the floating and fixed fingers. This change in capacitance represents acceleration on one axis. There is a system of fingers for all the three axes.
The sensor is very easy to wire; 5 volts to VCC, ground to GND, and feed each of the outputs to one of the analog input lines on the Arduino. All three axes are measured simultaneously. If you only want to use it to measure acceleration in one or two axes, you may simply only wire the ones you want to read.
This code assumes you've plugged the ADXL335's XOUT into A0, the YOUT into A1, and the ZOUT into A2. When you run this code, the return values will be formatted like:
256 369 301 257 369 310
This sort of formatting can be read by the Arduino IDE's "Serial plotter" to automatically plot the incoming data on a simple graph.
/* This sketch reads three analog pins and prints their
values to the serial monitor.
*/
// set up pin assignments
const int XPIN = A0;
const int YPIN = A1;
const int ZPIN = A2;
void setup() {
pinMode(XPIN, INPUT);
pinMode(YPIN, INPUT);
pinMode(ZPIN, INPUT);
Serial.begin(9600);
}
void loop() {
// store the analog reads of each pin into its own variable
int xVal = analogRead(XPIN);
int yVal = analogRead(YPIN);
int zVal = analogRead(ZPIN);
// print the values in format "123 456 789" for easy plotter graphing
Serial.print(xVal);
Serial.print(" "); // spaces between values to separate them
Serial.print(yVal);
Serial.print(" ");
Serial.println(zVal); // line break only needed after the final value
// slow down the loop a bit
delay(50);
}
| Part | Location | On floor | Backstock | |
|---|---|---|---|---|
| 0368 | accelerometer, 3-axis, analog output, ADXL335 | Input: Acceleration & Orientation | 9 | 16 |
| 0370 | accelerometer, 3-axis, digital output I²C (I2C) and SPI, ADXL345 | Input: Acceleration & Orientation | 0 | 0 |